hibernate - Could not determine type for: java.util.List -


i'm rather new hibernate , turns out it's not simple technology learn... in project use hibernate version 4.2.0.cr1. i'm trying create base class database entities, supposed contain identifier , date of creation. weird @ first, crated class user , userpicture without base class , worked fine , added it, though it's supposed work before, doesn't o_o , keeps on throwing weird exception list of pictures, not thrown before... keep on getting following stacktrace:

org.hibernate.mappingexception: not determine type for: java.util.list, @ table: user, columns: [org.hibernate.mapping.column(profilepicture)] @ org.hibernate.mapping.simplevalue.gettype(simplevalue.java:314) @ org.hibernate.mapping.simplevalue.isvalid(simplevalue.java:292) @ org.hibernate.mapping.property.isvalid(property.java:239) @ org.hibernate.mapping.persistentclass.validate(persistentclass.java:469) @ org.hibernate.mapping.unionsubclass.validate(unionsubclass.java:61) @ org.hibernate.cfg.configuration.validate(configuration.java:1283) @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1734) @ love.commons.database.dbmanager.<init>(dbmanager.java:28) @ love.commons.database.dbmanagertest.<clinit>(dbmanagertest.java:19) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:44) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:41) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:27) @ org.junit.runners.parentrunner.run(parentrunner.java:236) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197) 

abstractentity:

@entity @inheritance(strategy = inheritancetype.table_per_class) public abstract class abstractentity implements serializable{  private static final long serialversionuid = 1l;  protected long id;  protected date creationdate = new date();  @id @column(name="id") @generatedvalue(strategy=generationtype.table) public long getid() {     return id; }  public void setid(long id) {     this.id = id; }  @column @notnull @temporal(temporaltype.date) public date getcreationdate() {     return creationdate; }  public void setcreationdate(date creationdate) {     this.creationdate = creationdate; } } 

user:

@entity @table(name="user") public class user extends abstractentity {  private static final long serialversionuid = 1l;  @column (unique=true, length=30) @notnull private string login;  @column (length=32) @notnull private string password;  @notnull @email @column (unique=true, length=80) private string email;  @onetomany(cascade=cascadetype.all, fetch=fetchtype.lazy, mappedby="owner") private list<userpicture> profilepictures = new linkedlist<userpicture>();  public string getlogin() {     return login; }  public void setlogin(string login) {     this.login = login; }  public string getpassword() {     return password; }  public void setpassword(string password) {     this.password = password; }  public string getemail() {     return email; }  public void setemail(string email) {     this.email = email; }  @transient public void encryptpassword() {     this.password = md5(password); }  public list<userpicture> getprofilepicture() {     return collections.unmodifiablelist(profilepictures); }  public void addprofilepicture(userpicture profilepicture) {     profilepicture.setowner(this);     profilepictures.add(profilepicture); }  @transient private string md5(string input) {      string md5 = null;      if(null == input) return null;      try {         messagedigest digest = messagedigest.getinstance("md5");         digest.update(input.getbytes(), 0, input.length());         md5 = new biginteger(1, digest.digest()).tostring(16);      } catch (nosuchalgorithmexception e) {          e.printstacktrace();     }     return md5; }    } 

userpicture:

@entity public class userpicture extends abstractentity {  private static final long serialversionuid = 1l;  @column(length=734004) private byte [] picture = null;  @manytoone(fetch=fetchtype.lazy) @column(name="owner") @joincolumn(nullable=false,name="id") private user owner;  public userpicture() {     picture = null; }  public userpicture(inputstream stream) {     try {         this.picture = new byte[stream.available()];         stream.read(picture);     } catch (ioexception e) {         e.printstacktrace();     } }  public userpicture(byte [] picture) {     this.picture = picture; }  public byte[] getpicture() {     return picture; }  public void setpicture(byte[] picture) {     this.picture = picture; }  public user getowner() {     return owner; }  public void setowner(user owner) {     this.owner = owner; }    } 

so doing wrong? why keep on getting exception?

abstractentity must not annotated @entity , @inheritance. must annotated @mappedsuperclass. indeed, inheritance used inherit common attributes, , that's mappedsuperclass for.

the exception caused lack of coherence in position of mapping annotations. base superclass annotated getters, , subclasses annotate fields. hibernate uses position of id annotation determine access type of entity. since @id on getter, considers annotations placed on getters, , ignores placed on fields. put annotations either on fields (which recommend) or on getters.

moreover, getter badly named. should getprofilepictures() , not getprofilepicture().


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -