Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: overriding accesors in entity need tranisent declaration
PostPosted: Fri Aug 07, 2009 10:47 am 
Newbie

Joined: Thu May 28, 2009 8:52 pm
Posts: 7
This seems to be similar behavior as OpenJPA but a shade better in Hibernate.
The problem is, EclipseLink will not work with property defined as transient and returns null for such properties for the entity. So at this time, my application only works with EclipseLink but with neither Hibernate nor OpenJPA.

The orm.xml looks like this,

<access>PROPERTY</access>

<mapped-superclass class="UserModelBaseImpl">
<attributes>
<id name="id">
<generated-value strategy="IDENTITY"/>
</id>
<basic name="name">
<column name="firstName" />
</basic>
<basic name="lastName"/>
<basic name="age"/>
<basic name="wages"/>
<basic name="active">
<column name="ACTIVE_"/>
</basic>
<transient name="new"/>
</attributes>
</mapped-superclass>

<entity class="UserModelImpl">
<table name="User"/>
</entity>

Entity class is defined like this,

public class UserModelImpl extends UserModelBaseImpl {
public String getName() {
return super.getName();
}

public void setName(String name) {
super.setName(name);
}
}

The mapped-superclass UserModelBaseImpl also has getter/setter getName and setName (in addition to other accessors).

The reason for having overriding accessors in the entity, although it may not be apparent from this simple test case, is that the value object is conditionally manipulated.

This fails with an exception,
org.hibernate.MappingException: Duplicate property mapping of name found in Caused by: org.hibernate.MappingException: Duplicate property mapping of name found in com.example.model.impl.UserModelImpl
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:477)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:467)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1320)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

It works when name is declared as transient in the entity as shown below,
<entity class="UserModelImpl">
<table name="User"/>
<attributes>
<transient name="name"/>
</attributes>
</entity>

But now EclipseLink does not work and returns the UserModelImpl objects with name field blank.

I have asked this same question on OpenJPA alias as well,
http://n2.nabble.com/overriding-accesor ... 63414.html
OpenJPA has more serious problem that it never calls overridden accessors.
In case of hibernate, it at least works when the transient is defined and calls the overridden accessors, which is good but then EclipseLink fails.

Since the property is not really a transient, I think its a Hibernate/OpenJPA bug while I am tempted to believe EclispeLink is doing the right thing. Is that true?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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.