-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with derived property - requires a setter?
PostPosted: Tue May 30, 2006 4:54 am 
Newbie

Joined: Tue Feb 07, 2006 8:17 pm
Posts: 19
Using 3.1.2

I have a class & table with fields firstName & lastName. I want to define a derived property fullName as being firstName + ' ' + lastName. I can't get it to work.
My class has a getFullName() method but no setFullName() - as it's derived. When I run my app though, I get the following error :

org.hibernate.PropertyNotFoundException: Could not find a setter for property fullName in class it.orchestrate.oep.contact.Contact
at org.hibernate.property.BasicPropertyAccessor.createSetter(BasicPropertyAccessor.java:216)
at org.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:209)
at org.hibernate.mapping.Property.getSetter(Property.java:256)
at org.hibernate.tuple.PojoEntityTuplizer.buildPropertySetter(PojoEntityTuplizer.java:259)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:122)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)

My mapping file snippet :

<hibernate-mapping>
<!-- Stuff -->
<property name="firstName" length="128" type="string" column="firstname"/>
<property name="lastName" length="128" type="string" column="lastname"/>
<property name="fullName" insert="false" update="false" formula="(firstName + lastName)"/>

<!-- Stuff -->
</hibernate-mapping>

Anyone get ideas? I'm really stuck on this one. I've tried lots of different tags like including the type and length attributes to the derived property mapping but no go.

thanks,
Tom.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 12:26 pm 
Beginner
Beginner

Joined: Tue May 30, 2006 6:03 am
Posts: 20
Location: London
out of curiosity, why don't you just have a method on the object that concats them rather than have a non-changeable property in the hibernate? Hibernate will load both the first and last name fields anyway, so wouldn't the code be cleaner if logic like the concat was done in the java object? You would then also be able to add a space between the first and last name (if you wanted)


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 1:53 pm 
Newbie

Joined: Tue May 30, 2006 12:37 pm
Posts: 2
Location: Oregon, USA
Hi.

I would go with rkhanmoh's suggested approach, but if you still want to create the derived property in your mapping you need to create the setter setFullName() in your class ... Even though you don't use the setter in your application, Hibernate needs it for setting the value.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 2:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
or specify field access:
property name="fullName" access=field" formula="(firstName + lastName)"/>

but certainly changing getFullName() in your model to perform the concatenation seems like the much more reasonable approach.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 30, 2006 7:00 pm 
Newbie

Joined: Tue Feb 07, 2006 8:17 pm
Posts: 19
I want to do queries on the full name property and not have to do the concatenation each time. I didn't realise it would store a field for me, that's not what I want. I just wanted to be able to use it in the Criteria API

thanks for your responses.
Tom


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