java - JPA - using annotations in a model -
my application runs on jpa/hibernate, spring , wicket. i'm trying convert our orm xml files jpa annotations. annotated model looks this:
@entity @table(name = "app_user") public class user extends baseobject { private long id; private string firstname; private string lastname; private string email; @id @generatedvalue(strategy = generationtype.sequence) @column(name = "id") public long getid() { return id; } public void setid(long id) { this.id = id; } @column(name="first_name") public string getfirstname() { return firstname; } public void setfirstname(string firstname) { this.firstname = firstname; } @column(name="last_name") public string getlastname() { return lastname; } public void setlastname(string lastname) { this.lastname = lastname; } @column(name="email") public string getemail() { return email; } public void setemail(string email) { this.email = email; } /** * @return returns firstname , lastname */ public string getfullname() { return firstname + ' ' + lastname; } }
originally, though, without annotation , mapping described in user.hbm.xml:
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="org.appfuse.model.user" table="app_user"> <id name="id" column="id" unsaved-value="null"> <generator class="increment"/> </id> <property name="firstname" column="first_name" not-null="true"/> <property name="lastname" column="last_name" not-null="true"/> <property name="email" column="email"/> </class> </hibernate-mapping>
when delete mapping file , try use annotations, entitymanagerfactory doesn't created, exception
org.hibernate.propertynotfoundexception: not find setter property fullname in class org.appfuse.model.user.
there's no mapping set property, because it's convenience method. do wrong?
mark method @transient
hibernate ignore it:
/** * @return returns firstname , lastname */ @transient public string getfullname() { return firstname + ' ' + lastname; }
by default, looks getter mapped.
Comments
Post a Comment