Ilya
Ilya

Reputation: 29693

Hibernate mapping without getter

I have to properties that are mapped to one column

 <class name="Account" table="list">

  ...

<property name="creationDate" type="jodaTime" column="accdatetm" insert="false" update="false"/>
<property name="anotherDate" type="jodaTime" column="accdatetm" insert="false" update="false"/>  

creationDate have setter and getter in Account class

anotherDate haven't setter and getter in Account class

I got error

PropertyNotFoundException: Could not find a getter for anotherDate  

What can I do if I don't want have getter and setter for property, but want have a property?

Upvotes: 0

Views: 1788

Answers (3)

NimChimpsky
NimChimpsky

Reputation: 47290

What can I do if I don't want have getter and setter for property, but want have a property?

Change your mind, it is better to use a getter and setter for encapsulation and to maintain bean standards.

Upvotes: 1

Adisesha
Adisesha

Reputation: 5258

As you may know, Hibernate allows you to specify field or property access. Check this but you can not mix for same entity. If you want to mix, implement your own org.hibernate.property.PropertyAccessor as specified in the link above. Probably you can start with org.hibernate.property.BasicPropertyAccessor and delegate to org.hibernate.property.DirectPropertyAccessor when no getter or setter found.

As other's suggested, it is much more simpler to follow one convention rather then going through all this but sometimes you can not avoid the crazy situations :)

Upvotes: 0

shibbybird
shibbybird

Reputation: 1265

If you want to interact/display the database fields "createDate" or "anotherDate" in anyway you are going to need a getter. Hibernate assumes that you are going to use the property that you have declared, and its telling you that there is no supported way for you to use it without creating a getter. If you don't want to use the db field then don't include it as a property in the XML mappings. If this doesn't answer your question please give me some more detail on what you are trying to accomplish by referencing a field in a database that it doesn't sound like you want to use. Hope this helps.

Upvotes: 0

Related Questions