java - Hibernate mapping error - Unknown entity -
i'm hibernate newbie , im receiving error when trying persist object -
error -->unknown entity: org.apache.struts.register.model.event
in hibernate.cfg.xml
, define mapping as,
<mapping class="org.apache.struts.register.model.event"/>
my event class -
package org.apache.struts.register.model; import org.hibernate.annotations.entity; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.generatedvalue; import javax.persistence.table; @entity @table (name="event") public class event { @id @generatedvalue ( strategy = generationtype.auto) private int eventid; private string eventname; private string eventdescription; public string geteventname() { return eventname; } public void seteventname(string eventname) { this.eventname = eventname; } public string geteventdescription() { return eventdescription; } public void seteventdescription(string eventdescription) { this.eventdescription = eventdescription; } public string tostring(){ return this.eventname + "," + this.eventdescription; } }
eventdao -
package dao; import org.apache.struts.register.model.event; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.transaction; public class eventdao { public static boolean registerevent(event u) { sessionfactory sf = hibernateutil.getsessionfactory(); transaction t = null; try { session s = sf.opensession(); t = s.begintransaction(); // start new transaction s.persist(u); t.commit(); // commit transaction return true; } catch(exception ex) { system.err.println("error -->" + ex.getmessage()); if ( t!=null) t.rollback(); // rollback transaction on exception return false; } } }
system.err.println("error -->" + ex.getmessage())
, line throws exception.
thanks.
import org.hibernate.annotations.entity;
the hibernate @entity
not enough entity discovered. use javax.persistence.entity
instead.
@javax.persistence.entity still mandatory, @org.hibernate.annotations.entity not replacement.
Comments
Post a Comment