- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经做了一个在 hibernate 中使用数据库登录的示例。我的 Xml 和实体类是用户.java:
import java.util.Date;
import javax.persistence.Entity;
@Entity(name="User")
public class User {
private Integer userID;
private String username;
private String password;
private Date createdDate;
/**
* Default Constructor
*/
public User() {
super();
}
public User(Integer userID, String username, String password) {
this.userID = userID;
this.username = username;
this.password = password;
}
public Integer getUserID() {
return userID;
}
public void setUserID(Integer userID) {
this.userID = userID;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}//end of class()
UserBooks.java:
public class UsersBooks {
// Declaring all attributes
private double userID;
private String bookID;
private String permission;
// Constructors
public UsersBooks() {
super();
}
public UsersBooks(double userID, String bookID, String permission) {
super();
this.userID = userID;
this.bookID = bookID;
this.permission = permission;
}
// Getters and Setters
public double getUserID() {
return userID;
}
public void setUserID(double userID) {
this.userID = userID;
}
public String getBookID() {
return bookID;
}
public void setBookID(String bookID) {
this.bookID = bookID;
}
public String getPermission() {
return permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
// Overriding toString()
@Override
public String toString() {
return "UsersBooks [userID=" + userID + ", bookID=" + bookID
+ ", permission=" + permission + "]";
}//end of toString()
}//end of class
UserSocialInfo.java:
public class UserSocialInfo {
private int socialID;
private String loginProvider;
private String loginProviderUID;
private String UID;
private String nickname;
private String photoURL;
private String thumbnailURL;
private int birthDay;
private int birthMonth;
private int birthYear;
private String gender;
private String proxiedEmail;
private String country;
private String state;
private String city;
private String zip;
private String firstname;
private String lastname;
private String profileURL;
private int userID;
/**
*
*/
public UserSocialInfo() {
// TODO Auto-generated constructor stub
}
/**
* @return the socialID
*/
public int getSocialID() {
return socialID;
}
/**
* @param socialID the socialID to set
*/
public void setSocialID(int socialID) {
this.socialID = socialID;
}
/**
* @return the loginProvider
*/
public String getLoginProvider() {
return loginProvider;
}
/**
* @param loginProvider the loginProvider to set
*/
public void setLoginProvider(String loginProvider) {
this.loginProvider = loginProvider;
}
/**
* @return the loginProviderUID
*/
public String getLoginProviderUID() {
return loginProviderUID;
}
/**
* @param loginProviderUID the loginProviderUID to set
*/
public void setLoginProviderUID(String loginProviderUID) {
this.loginProviderUID = loginProviderUID;
}
/**
* @return the uID
*/
public String getUID() {
return UID;
}
/**
* @param uID the uID to set
*/
public void setUID(String uID) {
UID = uID;
}
/**
* @return the nickname
*/
public String getNickname() {
return nickname;
}
/**
* @param nickname the nickname to set
*/
public void setNickname(String nickname) {
this.nickname = nickname;
}
/**
* @return the photoURL
*/
public String getPhotoURL() {
return photoURL;
}
/**
* @param photoURL the photoURL to set
*/
public void setPhotoURL(String photoURL) {
this.photoURL = photoURL;
}
/**
* @return the thumbnailURL
*/
public String getThumbnailURL() {
return thumbnailURL;
}
/**
* @param thumbnailURL the thumbnailURL to set
*/
public void setThumbnailURL(String thumbnailURL) {
this.thumbnailURL = thumbnailURL;
}
/**
* @return the birthDay
*/
public int getBirthDay() {
return birthDay;
}
/**
* @param birthDay the birthDay to set
*/
public void setBirthDay(int birthDay) {
this.birthDay = birthDay;
}
/**
* @return the birthMonth
*/
public int getBirthMonth() {
return birthMonth;
}
/**
* @param birthMonth the birthMonth to set
*/
public void setBirthMonth(int birthMonth) {
this.birthMonth = birthMonth;
}
/**
* @return the birthYear
*/
public int getBirthYear() {
return birthYear;
}
/**
* @param birthYear the birthYear to set
*/
public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}
/**
* @return the gender
*/
public String getGender() {
return gender;
}
/**
* @param gender the gender to set
*/
public void setGender(String gender) {
this.gender = gender;
}
/**
* @return the proxiedEmail
*/
public String getProxiedEmail() {
return proxiedEmail;
}
/**
* @param proxiedEmail the proxiedEmail to set
*/
public void setProxiedEmail(String proxiedEmail) {
this.proxiedEmail = proxiedEmail;
}
/**
* @return the country
*/
public String getCountry() {
return country;
}
/**
* @param country the country to set
*/
public void setCountry(String country) {
this.country = country;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @param state the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the zip
*/
public String getZip() {
return zip;
}
/**
* @param zip the zip to set
*/
public void setZip(String zip) {
this.zip = zip;
}
/**
* @return the firstname
*/
public String getFirstname() {
return firstname;
}
/**
* @param firstname the firstname to set
*/
public void setFirstname(String firstname) {
this.firstname = firstname;
}
/**
* @return the lastname
*/
public String getLastname() {
return lastname;
}
/**
* @param lastname the lastname to set
*/
public void setLastname(String lastname) {
this.lastname = lastname;
}
/**
* @return the profileURL
*/
public String getProfileURL() {
return profileURL;
}
/**
* @param profileURL the profileURL to set
*/
public void setProfileURL(String profileURL) {
this.profileURL = profileURL;
}
/**
* @return the userID
*/
public int getUserID() {
return userID;
}
/**
* @param userID the userID to set
*/
public void setUserID(int userID) {
this.userID = userID;
}
}
我的 xml 文件用户.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.entities.User" table="users">
<id name="userID" type="long" column="userid">
<generator class="increment" />
</id>
<property name="username" column="username" />
<property name="password" column="password" />
<property name="userID" column="userid" insert="false" update="false"/>
<property name="createdDate" column="created_date" />
</class>
</hibernate-mapping>
UserBooks.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.entities.UsersBooks" table="users_books">
<id name="userID" type="long" column="user_id">
</id>
<property name="userID" column="user_id" insert="false" update="false"/>
<property name="bookID" column="book_id" insert="false" update="false"/>
<property name="permission" column="permissions" />
</class>
</hibernate-mapping>
UserSocialInfo.java:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.entities.UserSocialInfo" table="user_social_info">
<id name="socialID" type="long" column="social_id">
<generator class="increment" />
</id>
<property name="socialID" column="social_id" insert="false" update="false"/>
<property name="loginProvider" column="login_provider" />
<property name="loginProviderUID" column="login_provider_uid" insert="false" update="false"/>
<property name="UID" column="uid" insert="false" update="false"/>
<property name="nickname" column="nickname" />
<property name="photoURL" column="photo_url" />
<property name="thumbnailURL" column="thumbnail_url" />
<property name="birthDay" column="birthday" />
<property name="birthMonth" column="birthmonth" />
<property name="birthYear" column="birthyear" />
<property name="gender" column="gender" />
<property name="proxiedEmail" column="proxied_email" />
<property name="country" column="country" />
<property name="state" column="state" />
<property name="city" column="city" />
<property name="zip" column="zip" />
<property name="firstname" column="firstname" />
<property name="lastname" column="lastname" />
<property name="profileURL" column="profile_url" />
<property name="userID" column="user_id" insert="false" update="false"/>
</class>
</hibernate-mapping>
hibernate.cfg.xml:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="fabulaFactory">
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/appname
</property>
<property name="connection.username">
user
</property>
<property name="connection.password">
pwd
</property>
<property name="connection.pool_size">5</property>
<!-- SQL dialect -->
<property name="dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="com//hibernatexmlfiles//User.hbm.xml"/>
<mapping resource="com//hibernatexmlfiles//UsersBooks.hbm.xml"/>
<mapping resource="com//hibernatexmlfiles//UserSocialInfo.hbm.xml"/>
</session-factory>
</hibernate-configuration>
在执行项目时,我收到如下错误:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.fabulait.fabula.entities.User.userID
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:70)
at org.hibernate.tuple.AbstractTuplizer.setIdentifier(AbstractTuplizer.java:130)
at org.hibernate.persister.entity.BasicEntityPersister.setIdentifier(BasicEntityPersister.java:2930)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:146)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:477)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:472)
at com.service.UserService.storeSessionInfo(UserService.java:410)
at com.web.LoginUser.doPost(LoginUser.java:122)
at com.web.LoginUser.doGet(LoginUser.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:40)
... 32 more
请大家给点建议。
最佳答案
应该是
from User u where u.username=:username
我假设User
是与表映射的实体类(@Entity
)
关于java - 获取 hibernate 的 userId 的 PropertyAccessException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10913636/
我需要您在以下方面提供帮助。近一个月来,我一直在阅读有关任务和异步的内容。 我想尝试在一个简单的 wep api 项目中实现我新获得的知识。我有以下方法,并且它们都按预期工作: public Htt
我的可执行 jar 中有一个模板文件 (.xls)。不需要在运行时我需要为这个文件创建 100 多个副本(稍后将唯一地附加)。用于获取 jar 文件中的资源 (template.xls)。我正在使用
我在查看网站的模型代码时对原型(prototype)有疑问。我知道这对 Javascript 中的继承很有用。 在这个例子中... define([], function () { "use
影响我性能的前三项操作是: 获取滚动条 获取偏移高度 Ext.getStyle 为了解释我的应用程序中发生了什么:我有一个网格,其中有一列在每个单元格中呈现网格。当我几乎对网格的内容做任何事情时,它运
我正在使用以下函数来获取 URL 参数。 function gup(name, url) { name = name.replace(/[\[]/, '\\\[').replace(/[\]]/,
我最近一直在使用 sysctl 来做很多事情,现在我使用 HW_MACHINE_ARCH 变量。我正在使用以下代码。请注意,当我尝试获取其他变量 HW_MACHINE 时,此代码可以完美运行。我还认为
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 要求提供代码的问题必须表现出对所解决问题的最低限度的理解。包括尝试过的解决方案、为什么
由于使用 main-bower-files 作为使用 Gulp 的编译任务的一部分,我无法使用 node_modules 中的 webpack 来require 模块code> dir 因为我会弄乱当
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我使用 Gridlayout 在一行中放置 4 个元素。首先,我有一个 JPanel,一切正常。对于行数变大并且我必须能够向下滚动的情况,我对其进行了一些更改。现在我的 JPanel 上添加了一个 J
由于以下原因,我想将 VolumeId 的值保存在变量中: #!/usr/bin/env python import boto3 import json import argparse import
我正在将 MSAL 版本 1.x 更新为 MSAL-browser 的 Angular 。所以我正在尝试从版本 1.x 迁移到 2.X.I 能够成功替换代码并且工作正常。但是我遇到了 acquireT
我知道有很多关于此的问题,例如 Getting daily averages with pandas和 How get monthly mean in pandas using groupby但我遇到
This is the query string that I am receiving in URL. Output url: /demo/analysis/test?startDate=Sat+
我正在尝试使用 javascript 中的以下代码访问 Geoserver 层 var gkvrtWmsSource =new ol.source.ImageWMS({ u
API 需要一个包含授权代码的 header 。这就是我到目前为止所拥有的: var fullUrl = 'https://api.ecobee.com/1/thermostat?json=\{"s
如何获取文件中的最后一个字符,如果是某个字符,则删除它而不将整个文件加载到内存中? 这就是我目前所拥有的。 using (var fileStream = new FileStream("file.t
我是这个社区的新手,想出了我的第一个问题。 我正在使用 JSP,我成功地创建了 JSP-Sites,它正在使用jsp:setParameter 和 jsp:getParameter 具有单个字符串。
在回答 StoreStore reordering happens when compiling C++ for x86 @Peter Cordes 写过 For Acquire/Release se
我有一个函数,我们将其命名为 X1,它返回变量 Y。该函数在操作 .on("focusout", X1) 中使用。如何获取变量Y?执行.on后X1的结果? 最佳答案 您可以更改 Y 的范围以使其位于函
我是一名优秀的程序员,十分优秀!