-->
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: Getter & Setter and Hibernate Mapping files
PostPosted: Tue May 04, 2010 5:31 am 
Newbie

Joined: Tue May 04, 2010 5:21 am
Posts: 6
Hello to all,

I have a developed system. now i want to add hibernate in it. My issue is that my Bean contains setter,getter which does not follow standard java convention. So whenever i try to map my Bean to corresponding table,It throws exception getter/setter could not found while configuring SessionFactory.

The two options that i could think of are:

1. I generate new getter/setter according to standard convention and within them i called my existing getter/setter

2. Other is I change property name in XML mapping file so that it can find existing getter/setter (which is not following standard convention. )

Is there any third option as such I feel first option is better by considering future scenario also...but somehow can i mention which getter/setter to be called for the property in XML file?

Please help me out...

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Getter & Setter and Hibernate Mapping files
PostPosted: Tue May 04, 2010 6:33 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
I think you have to use field access in this case (like that Hibernate doesn't use getters/setters to manage persistent properties)

a good literature about it: http://javaprogrammingtips4u.blogspot.c ... ss-in.html

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Getter & Setter and Hibernate Mapping files
PostPosted: Tue May 04, 2010 6:46 am 
Newbie

Joined: Tue May 04, 2010 5:21 am
Posts: 6
Thank you hallmit..But I am not opting to use Annotations..I prefer XML files which will lead to easy modification....

Is that the same thing can't be done from XML file?


Top
 Profile  
 
 Post subject: Re: Getter & Setter and Hibernate Mapping files
PostPosted: Tue May 04, 2010 6:56 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
each annotation has an equivalent xml mapping. you can control access strategy on the property level like this:
Code:
<property name="field" column="MY_FIELD" access="field"/>

or you can set the access strategy for all class mappings:
Code:
<hibernate-mapping ... default-access="field">

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Getter & Setter and Hibernate Mapping files
PostPosted: Tue May 04, 2010 7:04 am 
Newbie

Joined: Tue May 04, 2010 5:21 am
Posts: 6
That was really helpful..You made my day...

Thanks a lot...


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.