-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Javassist Enhancement failed
PostPosted: Fri Jan 16, 2009 4:06 pm 
Newbie

Joined: Wed Jun 01, 2005 7:51 pm
Posts: 13
This program works with 3.2.1. Simply replacing the hibernate3.jar and adding the new
required jars in 3.3, the program throws org.hibernate.HibernateException: Javassist Enhancement failed:. Note that this is a multii-threaded app (and, yes, each app has it's own session -- remember this works in 3.2.1) and this error only occurs occasionally. Also, occasionally, rather than throwing this hibernate exception, the user object is returned as null, i.e. hibernate fails to instantiate it. This doesn't occur in the database due to not null and FK constraints in the user login name map table. This looks very much like a hibernate bug in the switch to javassist (or a bug in javaassist) as the NPE occurs in generated code. Anyone have any ideas? Any developers wish to comment?

Thanks,
Brian


Hibernate version: 3.3.1GA

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="com.timestock.tess.data.objects.UserLoginNameMap"
table="ts_user_logins_map"


>
<composite-id
name="key"
class="com.timestock.tess.data.objects.UserLoginNameMapKey"
>
<key-many-to-one name="appDef" class="com.timestock.tess.data.objects.AppDef">
<column name="ts_app_id" not-null="true" />
</key-many-to-one>
<key-property name="loginName" type="java.lang.String">
<column name="ts_login_name" length="200" not-null="true" />
</key-property>
</composite-id>
<version name="version" column="version_info" type="long" />

<many-to-one name="user" class="com.timestock.tess.data.objects.User">
<column name="ts_user_id" not-null="true" />
</many-to-one>

<many-to-one
name="appType"
class="com.timestock.tess.data.objects.AppType"
>
<column name="ts_apptype_id" not-null="true" />
</many-to-one>

<property
name="rawLoginName"
type="java.lang.String"
>
<column name="ts_raw_login_name" length="200" not-null="true" />
</property>

<property
name="createDate"
type="java.util.Date"
>
<column name="ts_create_date" scale="23" precision="3" not-null="true" />
</property>

<property
name="deleteDate"
type="java.util.Date"
>
<column name="ts_delete_date" scale="23" precision="3" not-null="false" />
</property>

<property
name="softDelete"
type="java.lang.Boolean"
>
<column name="ts_soft_delete" not-null="true" />
</property>



</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class
name="com.timestock.tess.data.objects.User"
table="ts_users"


>
<id
name="id"
type="java.lang.Long"
>
<column name="ts_id" not-null="true" unique="true" />
<generator class="com.timestock.tess.util.IncrementGenerator" />
</id>
<version name="version" column="version_info" type="long" />

<property
name="incarnationId"
type="java.lang.Long"
>

<column name="ts_incarnation_id" not-null="true" />
</property>

<many-to-one
name="userImportance"
class="com.timestock.tess.data.objects.UserImportance"
>
<column name="ts_importance_id" not-null="true" />
</many-to-one>

<many-to-one
name="userDefGroup"
class="com.timestock.tess.data.objects.UserDefGroup"
>
<column name="ts_userdef_group_id" not-null="true" />
</many-to-one>

<property
name="firstName"
type="java.lang.String"
>
<column name="ts_first_name" length="200" not-null="true" />
</property>

<property
name="lastName"
type="java.lang.String"
>
<column name="ts_last_name" length="200" not-null="true" />
</property>

<property
name="loginName"
type="java.lang.String"
>

<column name="ts_login_name" length="200" not-null="false" />
</property>

<property
name="lastActiveDate"
type="java.util.Date"
>
<column name="ts_last_active_time" scale="23" precision="3" not-null="true" />
</property>

<property
name="inactivationDate"
type="java.util.Date"
>
<column name="ts_inactivation_time" scale="23" precision="3" not-null="false" />
</property>

<property
name="active"
type="java.lang.Boolean"
>
<column name="ts_active" not-null="true" />
</property>

<property
name="importanceInherited"
type="java.lang.Boolean"
>
<column name="ts_importance_inherited" not-null="true" />
</property>

<property
name="successRateSla"
type="java.lang.Float"
>
<column name="ts_success_rate_sla" length="24" not-null="true" />
</property>

<property
name="successRateSlaInherited"
type="java.lang.Boolean"
>
<column name="ts_success_sla_inherited" not-null="true" />
</property>

<property
name="sigmaSla"
type="java.lang.Float"
>
<column name="ts_sigma_sla" length="24" not-null="true" />
</property>

<property
name="sigmaSlaInherited"
type="java.lang.Boolean"
>
<column name="ts_sigma_sla_inherited" not-null="true" />
</property>

<property
name="tranTimeSla"
type="java.lang.Integer"
>
<column name="ts_tran_time_sla" length="10" not-null="true" />
</property>

<property
name="tranTimeSlaInherited"
type="java.lang.Boolean"
>
<column name="ts_tran_time_sla_inherited" not-null="true" />
</property>

<property
name="collectUserStats"
type="java.lang.Boolean"
>
<column name="ts_collect_stats" not-null="true" />
</property>

<property
name="collectUserStatsInherited"
type="java.lang.Boolean"
>
<column name="ts_collect_stats_inherited" not-null="true" />
</property>

<property
name="softDelete"
type="java.lang.Boolean"
>
<column name="ts_soft_delete" not-null="true" />
</property>


<set optimistic-lock="false" lazy="true" inverse="true" name="setOfUserGroupUserMap">
<key column="ts_user_id" on-delete="cascade" />
<one-to-many class="com.timestock.tess.data.objects.UserGroupUserMap" />
</set>

<set optimistic-lock="false" lazy="true" inverse="true" name="setOfUserLoginNameMap">
<key column="ts_user_id" on-delete="cascade" />
<one-to-many class="com.timestock.tess.data.objects.UserLoginNameMap" />
</set>

<set optimistic-lock="false" lazy="true" inverse="true" name="setOfUserSessionIdMap">
<key column="ts_user_id" on-delete="cascade" />
<one-to-many class="com.timestock.tess.data.objects.UserSessionIdMap" />
</set>

<set optimistic-lock="false" lazy="true" name="setOfDefect">
<key column="ts_user_id" />
<one-to-many class="com.timestock.tess.data.objects.Defect" />
</set>



<!--
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetGroupUserDaily"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetGroupUserDaily"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetUserDaily"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetUserDaily"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranUnitUserMonthly"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranUnitUserMonthly"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetGroupUserWeekly"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetGroupUserWeekly"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetUserInterval"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetUserInterval"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetUserMonthly"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetUserMonthly"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetGroupUserInterval"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetGroupUserInterval"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranUnitUserDaily"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranUnitUserDaily"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetUserWeekly"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetUserWeekly"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranUnitUserInterval"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranUnitUserInterval"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranSetGroupUserMonthly"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranSetGroupUserMonthly"
/>
</set>
<set optimistic-lock="false" lazy="true"
name="setOfStatsTranUnitUserWeekly"
>
<key>
<column name="ts_user_id" not-null="true" />
</key>
<one-to-many
class="com.timestock.tess.data.objects.StatsTranUnitUserWeekly"
/>
</set>
-->
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
much too much to include here. I've attempted to include the relevant lines
based on the stack trace included below.

excerpt from DefectProcessor (see stack trace):

readSession = sessionFactory.openSession();
writeSession = sessionFactory.openSession();
dbUtils = new DbUtils(userManager, writeSession);

----------------------------------------------------------------------------------------
excerpt from DbUtils (session == writeSession):

ArrayList<UserLoginNameMap> loginMaps =
(ArrayList) userManager._findInSession(UserLoginNameMap.class, filter, session, false);

----------------------------------------------------------------------------------------
public List _findInSession(Class clazz, Filter filter, Session session, boolean excludeDeletedObjects)
{
List objs = null;
Transaction tx = session.beginTransaction();

try
{
objs = objectDao.find(filter, null, session, clazz, excludeDeletedObjects);
}
finally
{
try { tx.rollback(); }
catch (Exception ex1) {}
}

return objs;
}

----------------------------------------------------------------------------------------------
public List find(Filter filter, Integer maxResults, Session session, Class clazz,
boolean excludeDeletedObjects)
{
Criteria criteria = session.createCriteria(clazz);
List<KeyValuePair> keyValuePairs = filter.getKeyValuePairs();

// exlude deleted items
if (excludeDeletedObjects) criteria.add(Restrictions.eq("softDelete", Boolean.FALSE));

// limit the result set
if (maxResults != null)
{
criteria.setFirstResult(0);
criteria.setMaxResults(maxResults);
}

//add the filter(s)
for (KeyValuePair keyValuePair : keyValuePairs)
{
addExpression(criteria, keyValuePair);
}

if (null != getDefaultOrder()) criteria.addOrder(getDefaultOrder());

return criteria.list();
}


Full stack trace of any exception that occurs:
org.hibernate.HibernateException: Javassist Enhancement failed: com.timestock.tess.data.objects.User
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:142)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:72)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:402)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3483)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:298)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:219)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:905)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:873)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
at org.hibernate.type.EntityType.resolve(EntityType.java:412)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at com.timestock.tess.data.base._SpringBaseRootDAO.find(_SpringBaseRootDAO.java:434)
at com.timestock.tess.services.managers.ObjectManager._findInSession(ObjectManager.java:367)
at com.timestock.tess.services.managers.ObjectManager$$FastClassByCGLIB$$b473326b.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:608)
at com.timestock.tess.services.managers.UserManager$$EnhancerByCGLIB$$a868f8f3._findInSession(<generated>)
at com.timestock.tess.util.DbUtils.getLoginMap(DbUtils.java:1084)
at com.timestock.tess.util.DbUtils.getUserFromLoginMap(DbUtils.java:1049)
at com.timestock.tess.util.DbUtils.findOrCreateUser(DbUtils.java:468)
at com.timestock.tess.util.DbUtils.getUserInfo(DbUtils.java:430)
at com.timestock.tess.services.processors.DefectProcessor.getUser(DefectProcessor.java:1135)
at com.timestock.tess.services.processors.DefectProcessor.process(DefectProcessor.java:392)
at com.timestock.tess.services.tim.TimIo$ProcessingQueueThread.processDefectData(TimIo.java:1120)
at com.timestock.tess.services.tim.TimIo$ProcessingQueueThread.run(TimIo.java:1023)
Caused by: java.lang.NullPointerException
at javassist.util.proxy.RuntimeSupport$DefaultMethodHandler.invoke(RuntimeSupport.java:37)
at com.timestock.tess.data.objects.User_$$_javassist_47.initialize(User_$$_javassist_47.java)
at com.timestock.tess.data.base.BaseUser.<init>(BaseUser.java:42)
at com.timestock.tess.data.objects.User.<init>(User.java:19)
at com.timestock.tess.data.objects.User_$$_javassist_47.<init>(User_$$_javassist_47.java)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:139)
... 34 more

Name and version of the database you are using: postgres 8.3.5

The generated SQL (show_sql=true): none


Top
 Profile  
 
 Post subject: I met the same error with simple demo code.
PostPosted: Sat Jan 17, 2009 11:24 pm 
Newbie

Joined: Sat Jan 17, 2009 11:13 pm
Posts: 2
This is the code I run.
jdk 1.5
The latest Hibernate viersion downloaded last week
My sql 5.0 without connection pool.

Code:
    public static void loadData(String id,String id2) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
//        Customer customer1 = (Customer) session.get(Customer.class, id);//        System.out.println("customer1 = " + customer1);

        CustomerOrder order = (CustomerOrder)session.get(CustomerOrder.class,id2) ;
        System.out.println("order = " + order);
        System.out.println("order.getCustomer() = " + order.getCustomer());
//        System.out.println("order3.getCustomer() .getName() = " + order3.getCustomer().getName());
        session.getTransaction().commit();
    }


If I load a Customer class befor load the order, following code runs ok,
but if i comment the code "Customer customer1 = (Customer) session.get(Customer.class, id);" there will throw a exception

Code:
Hibernate: select customeror0_.id as id1_0_, customeror0_.orderNumber as orderNum2_1_0_, customeror0_.customer as customer1_0_ from CustomerOrder customeror0_ where customeror0_.id=?
Exception in thread "main" org.hibernate.HibernateException: Javassist Enhancement failed: com.yishi2009.learn2.Customer


Code:
Caused by: java.lang.InstantiationException: com.yishi2009.learn2.Customer_$$_javassist_1
   at java.lang.Class.newInstance0(Class.java:335)
   at java.lang.Class.newInstance(Class.java:303)
   at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:139)
   ... 39 more



code for the Customer , and order class are as following

Code:
package com.yishi2009.learn2;

/**
* Created by IntelliJ IDEA.
* User: fayan li
* Date: 2009-1-17
* Time: 22:22:57
* To change this template use File | Settings | File Templates.
*/
public class Customer {
    private String id;
    private String name;

    private Customer() {

    }

    public Customer(String str) {
        this.name = str;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping
   package="com.yishi2009.learn2">
    <class name="Customer">
        <id name="id" >
            <generator class="uuid"/>
        </id>
        <property name="name"/>
    </class>
</hibernate-mapping>


Code:
package com.yishi2009.learn2;

/**
* Created by IntelliJ IDEA.
* User: fayan li
* Date: 2009-1-17
* Time: 22:23:43
* To change this template use File | Settings | File Templates.
*/
public class CustomerOrder {
    private String id;
    private String orderNumber;
    private Customer customer;

    private CustomerOrder() {

    }

    public CustomerOrder(String s, Customer customer) {
        this.customer = customer;
        this.orderNumber = s;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
}


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping
   package="com.yishi2009.learn2">
    <class name="com.yishi2009.learn2.CustomerOrder">
        <id name="id" >
            <generator class="uuid"/>
        </id>
        <property name="orderNumber"/>
        <many-to-one name="customer" not-null="true"/>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 17, 2009 11:25 pm 
Newbie

Joined: Sat Jan 17, 2009 11:13 pm
Posts: 2
I thought this error may have some relationship with the lazy feature.


Top
 Profile  
 
 Post subject: Same probleman
PostPosted: Wed Feb 04, 2009 8:53 am 
Newbie

Joined: Tue Jul 12, 2005 2:46 pm
Posts: 13
Location: BS2
i have the same problem but i could not resolve it


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 02, 2009 6:25 pm 
Newbie

Joined: Mon Mar 02, 2009 6:23 pm
Posts: 5
Changing the constructor from private to public fixed it for me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 5:17 pm 
Newbie

Joined: Sun Nov 18, 2007 4:57 pm
Posts: 5
Has anyone discovered what was wrong with this?
My classes have public constructors.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 29, 2009 6:23 am 
Newbie

Joined: Sun Mar 29, 2009 6:20 am
Posts: 1
Try providing public constructors without args.


Top
 Profile  
 
 Post subject: Re: Javassist Enhancement failed
PostPosted: Fri Jun 26, 2009 6:12 pm 
Newbie

Joined: Fri Jun 26, 2009 6:10 pm
Posts: 1
It works when I provided a default constructor =D


Top
 Profile  
 
 Post subject: Re: Javassist Enhancement failed
PostPosted: Tue Jul 28, 2009 11:42 am 
Newbie

Joined: Thu Jul 23, 2009 12:32 pm
Posts: 5
Protected ctors work too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.