-->
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.  [ 2 posts ] 
Author Message
 Post subject: tyro first of hibernate error
PostPosted: Wed Dec 13, 2006 8:46 am 
Newbie

Joined: Tue Dec 12, 2006 11:50 pm
Posts: 10
[id] [int] IDENTITY (1, 1) NOT NULL ,PRIMARY KEY,UNIQUE

what must versus id of manipulation me!thank you

Use hibernate save:
namely error:

LogicDAO dao = new LogicDAO();
Logic logic=new Logic();
try {
Session s=dao.getSession();
Transaction t=s.beginTransaction();
logic.setUsername("aa");
logic.setPwd("aa");
dao.save(logic);
t.commit();

} catch (HibernateException e) {
System.err.println("Entity retrieval failed.");
e.printStackTrace();
} finally {
try {
dao.getSession().close();
} catch (Exception e) {
e.printStackTrace();
}
}

Error is:

Entity retrieval failed.
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.hibernate.db.Logic
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at com.hibernate.db.LogicDAO.save(LogicDAO.java:27)
at com.hibernate.db.A.main(A.java:22)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 2:34 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
This is a very common mistake : you seem to have specified something like <generator class="assigned"> inside the id tag of Logic.hbm.xml (or nothing 'cause I think this is the default), so your code is missing the setId() part.

If you want Hibernate to take care of this primary key (generating one when none is present : for new objects), use <generator class="native"> and create a sequence named hibernate_sequence in the db if it supports sequence. If not, hibernate should automatically use the right thing (identity, etc.) if you specified the right dialect in you hibernate.cfg.xml file.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.