-->
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.  [ 6 posts ] 
Author Message
 Post subject: Possible bug mapping an Entity ?
PostPosted: Thu May 03, 2007 3:14 pm 
Newbie

Joined: Thu Apr 26, 2007 2:42 pm
Posts: 6
I have an Entity called Product, who has an attribute called 'unique' (which is String, with values 'Y' or 'N', the database was pre-existent), which has the methods: String getUnique() and setUnique(String x). Alse, we have a convenience method: boolean isUnique(), which is marked as @Transient to tell the ORM that it shouldn't map that attribute with any column.

When Hibernate is constructing the mapping (on the EntityManagerFactory construction), there is a class that find the accessors of each property (org.hibernate.property.BasicPropertyAccessor.java). When looking for the 'unique' property, sometimes it finds the get/set pair, and mark the property as a String, but... sometimes (seems that depends on the order that it gets the method array) it finds the 'isUnique' method first (it stop when find the first 'get' or 'is'), and mark the property as Boolean, generating a ClassCastException error when trying to persist a new instance of this entity.

Seems that Hibernate don't care about the @Transient annotation when try to find the accessors of each property.

Could it be a bug ? Does anyone has any information about this ?

(We use a work around at the moment changing the name of the isUnique method, but we wanted to check in the forum before reporting this as a bug).


DETAIL:

Hibernate version: hibernate-entitymanager-3.3.1.GA hibernate-3.2.3.ga hibernate-annotations-3.3.0.GA

Full stack trace of any exception that occurs:

java.lang.ClassCastException: java.lang.Boolean
at org.hibernate.type.StringType.toString(StringType.java:44)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:87)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:60)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1910)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1887)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2117)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2503)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:267)
at crm.core.appl.FwkJDBCTransactionManager.finishCurrentTransaction(FwkJDBCTransactionManager.java:85)
at crm.core.wfl.appl.FwkProcessInternalJDBCBDlg.prcStartProcess(FwkProcessInternalJDBCBDlg.java:97)
at crm.core.wfl.appl.FwkProcessAppl.prcStartProcess(FwkProcessAppl.java:51)
at crm.core.wfl.appl.FwkProcessJDBCBDlg.prcStartProcess(FwkProcessJDBCBDlg.java:45)
at crm.core.wfl.appl.FwkClientInteractiveProcessAppl.prcStartProcess(FwkClientInteractiveProcessAppl.java:56)
at crm.core.wfl.appl.FwkClientInteractiveProcessJDBCBDlg.prcStartProcess(FwkClientInteractiveProcessJDBCBDlg.java:59)
at crm.appl.rec.integracion.common.appl.RecCommonAppl.abrirWfl(RecCommonAppl.java:87)
at crm.appl.rec.integracion.common.appl.RecCommonJDBCBDlg.abrirWfl(RecCommonJDBCBDlg.java:52)
at crm.appl.rec.integracion.test.Test.main(Test.java:19)

Name and version of the database you are using: Oracle 9i


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:20 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
Why not simply use isUnique() and setUnique()? I don't see why you need the extra getter.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:23 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
You'd need something like the following in your hibernate.properties:

Code:
hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:38 pm 
Newbie

Joined: Thu Apr 26, 2007 2:42 pm
Posts: 6
Kerstetter,

I got a getUnique and setUnique with a String because the field in the database (which I can't change) is String.

The other method (isUnique) that I introduced, I don't want to map it with any field in the database.

My questions is why the engine takes that method if it's marked as '@Transient'? Is this a bug?

Yes, is possible make a sustitution, but I just want to figure out, if this situation, is a bug.

Thanks for your replay anyway :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:42 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
It's not a bug. It's part of the JavaBean specification. For every property you need 1 g/set pair. For booleans, you can have is/set. You can't have both.

Hibernate can *translate* the strings 'Y', and 'N' to boolean values via the query substitution entry in hibernate.properties I posted.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A user @Type will help you hide the inconsistency of your database and solve your problem.
The type will have to convert a boolean to whatever your DB digests

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.