您好,我正在使用developenig Java Web应用程序,并且在尝试使用hibernate模式获取数据时遇到了下一个异常
java.lang.ClassCastException: com.digitalticket.model.UserType_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
这里stacktrace
java.lang.ClassCastException: com.digitalticket.model.UserType_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:147)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:75)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:771)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4613)
at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:349)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:270)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:989)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
at org.hibernate.type.EntityType.resolve(EntityType.java:502)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:170)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1114)
at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
at org.hibernate.loader.Loader.doQuery(Loader.java:920)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2553)
at org.hibernate.loader.Loader.doList(Loader.java:2539)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
at org.hibernate.loader.Loader.list(Loader.java:2364)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1682)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
at com.digitalticket.model.DAO.fetchAll(DAO.java:204)
at com.digitalticket.controller.IndexController.handleRequestInternal(IndexController.java:22)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:154)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:550)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
这是我的代码
public T fetchAll(tClass<T> className) {
Session s = sessionFactory.getCurrentSession();
s.beginTransaction();
try {
List<T> results = (List<T>) sessionFactory.getCurrentSession()
.createCriteria(className)
.list();
s.getTransaction().commit();
return results();
} catch (NullPointerException ex) {
return null;
}
catch (RuntimeException re) {
s.getTransaction().rollback();
throw re;
} finally {
}
}
这是我的对象
public class User implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -2383716625869790753L;
private long userId;
private UserType userType;
private String email;
private String password;
private String name;
private String surname;
private String middlename;
private Set<Ticket> tickets = new HashSet<Ticket>(0);
private Set<Organization> organizations = new HashSet<Organization>(0);
public User() {
}
public User(long userId, String email, String password, String name,
String surname) {
this.userId = userId;
this.email = email;
this.password = password;
this.name = name;
this.surname = surname;
}
public User(long userId, UserType userType, String email, String password,
String name, String surname, String middlename,
Set<Ticket> tickets, Set<Organization> organizations) {
this.userId = userId;
this.userType = userType;
this.email = email;
this.password = password;
this.name = name;
this.surname = surname;
this.middlename = middlename;
this.tickets = tickets;
this.organizations = organizations;
}
public long getUserId() {
return this.userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public UserType getUserType() {
return this.userType;
}
public void setUserType(UserType userType) {
this.userType = userType;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return this.surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getMiddlename() {
return this.middlename;
}
public void setMiddlename(String middlename) {
this.middlename = middlename;
}
public Set<Ticket> getTickets() {
return this.tickets;
}
public void setTickets(Set<Ticket> tickets) {
this.tickets = tickets;
}
public Set<Organization> getOrganizations() {
return this.organizations;
}
public void setOrganizations(Set<Organization> organizations) {
this.organizations = organizations;
}
}
public class UserType implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -206438165274679246L;
private long userTypeCode;
private String userTypeName;
private Set<User> users = new HashSet<User>(0);
public UserType() {
}
public UserType(long userTypeCode, String userTypeName) {
this.userTypeCode = userTypeCode;
this.userTypeName = userTypeName;
}
public UserType(long userTypeCode, String userTypeName, Set<User> users) {
this.userTypeCode = userTypeCode;
this.userTypeName = userTypeName;
this.users = users;
}
public long getUserTypeCode() {
return this.userTypeCode;
}
public void setUserTypeCode(long userTypeCode) {
this.userTypeCode = userTypeCode;
}
public String getUserTypeName() {
return this.userTypeName;
}
public void setUserTypeName(String userTypeName) {
this.userTypeName = userTypeName;
}
public Set<User> getUsers() {
return this.users;
}
public void setUsers(Set<User> users) {
this.users = users;
}
}
这是映射
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 16, 2014 10:31:53 AM by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
<class name="com.digitalticket.model.User" table=""USER"">
<id name="userId" type="long">
<column name="USER_ID" precision="10" scale="0" />
<generator class="assigned" />
</id>
<many-to-one class="com.digitalticket.model.UserType"
fetch="select" name="userType">
<column name="USER_TYPE" precision="10" scale="0" />
</many-to-one>
<property generated="never" lazy="false" name="email" type="string">
<column length="20" name="EMAIL" not-null="true" unique="true" />
</property>
<property generated="never" lazy="false" name="password"
type="string">
<column length="32" name="PASSWORD" not-null="true" />
</property>
<property generated="never" lazy="false" name="name" type="string">
<column length="64" name="NAME" not-null="true" />
</property>
<property generated="never" lazy="false" name="surname" type="string">
<column length="64" name="SURNAME" not-null="true" />
</property>
<property generated="never" lazy="false" name="middlename"
type="string">
<column length="64" name="MIDDLENAME" />
</property>
<set fetch="select" inverse="true" lazy="true" name="tickets"
sort="unsorted" table="TICKET">
<key>
<column name="USER" precision="10" scale="0" />
</key>
<one-to-many class="com.digitalticket.model.Ticket" />
</set>
<set fetch="select" lazy="true" name="organizations" sort="unsorted"
table="AUDITOR">
<key>
<column name="USER" not-null="true" precision="9" scale="0" />
</key>
<many-to-many entity-name="com.digitalticket.model.Organization"
unique="false">
<column name="ORGANIZATION" not-null="true" precision="10"
scale="0" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Mar 16, 2014 10:31:53 AM by Hibernate Tools 4.0.0 -->
<hibernate-mapping>
<class name="com.digitalticket.model.UserType" table="USER_TYPE">
<id name="userTypeCode" type="long">
<column name="USER_TYPE_CODE" precision="10" scale="0" />
<generator class="assigned" />
</id>
<property name="userTypeName" type="string">
<column name="USER_TYPE_NAME" length="40" not-null="true" unique="true" />
</property>
<set name="users" table="USER" inverse="true" lazy="true" fetch="select">
<key>
<column name="USER_TYPE" precision="10" scale="0" />
</key>
<one-to-many class="com.digitalticket.model.User" />
</set>
</class>
</hibernate-mapping>
我正在使用Oracle Weblogic 12c服务器
通过将我的pom.xml中的依赖项更改为较旧的版本4.3.4进行了修复。最终错误已在4.3.4。最终版本更改为4.2.7。
不要以为这是最好的解决方案,但我还没有找到其他解决方案。
问题内容: 我有一个Java EE应用程序,并且使用了Hibernate。在域对象中,我将List / ArrayList更改为Set / HashSet,因为最好使用Sets。 但是在我的Dao实现中,我遇到了一个问题: 在这里我得到一个错误: 我应该怎么做才能避免这个错误? 预先感谢您和最诚挚的问候。 问题答案: 将返回结果项的数组列表,如果需要在Set中使用它,可以按照代码所示进行制作
问题内容: 尝试将结果集强制转换为映射类时,我收到了hibernate类的类强制转换异常…我能够查看返回的结果集中的数据…但是它以Object []的形式返回我可以将Object []设置为List …我可以正确地进行hibernate映射吗?我从查询中获取了正确的数据,但映射不正确… 映射 映射类 参加班 主要 问题答案: 对于测试,我建议您在产生类强制转换异常的语句周围放置一个try-catc
问题内容: 我有一个“复杂”的问题。 我正在使用Hibernate / JPA与数据库进行事务。 我不是DBA,客户端使用了我的应用程序,即RESTful Web服务。我的问题是数据库已更改(不是很频繁,但仍在更改)。另外,客户端并不总是尊重我的应用程序的输入(长度,类型等)。发生这种情况时,Hibernate会引发异常。异常很难翻译和从日志中读取,因为它具有嵌套的异常并且由很多文本组成:就像我说
问题内容: 我在注释和上遇到了问题。在Hibernate中运行代码时,我得到: 引起原因:org.hibernate.PropertyAccessException:无法通过com.test.entities.EmployeeId.serverId的反射设置器设置字段值 但是,让我们从头开始…我有一个实体的复合主键,它由指向其他两个实体(和)的外键组成。为了设计简洁,我在Employee实体中使用
问题内容: 我试图配置我的实体,但是休眠抛出以下异常: 这些是我的实体: 下一个: 最后一个: Hibernate无法确定位于SDUser实体中的productAccess列的类型。我是Hibernate的新手,我不知道发生了什么。 我应该提供某种ID吗? 谢谢!! 问题答案: 在中,您需要在上添加关联信息:
Deal和DealDocument类是相同的。Deal document类如下所示: 你觉得问题可能是什么?它似乎是随机出现的,好像它工作正常,但在时间内系统退化 *更新*:这是我如何配置模型映射器的:ModelMapper.GetConfiguration().SetAmbiguity忽略(false).SetFieldMatchingEnabled(true).SetMatchingStrat