-->
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: hibernateexception
PostPosted: Fri Jul 07, 2006 7:55 am 
Newbie

Joined: Fri Jul 07, 2006 7:30 am
Posts: 1
I managed to get Hibernate run on my WAS 6.0 test environment and Im using Hibernate 3.2 and Struts 1.1

struts-config.xml
<plug-in className="toto.data.HibernateUtil">
<set-property property="_configFilePath" value="/WEB-INF/hibernate.cfg.xml"/>
<set-property property="storedInServletContext " value="true"/>
</plug-in>

hibernate.cfg.xml
------------------------
<hibernate-configuration>
<session-factory name="hibernate/SessionFactory">
<!-- datasource connection properties -->
<property name="connection.datasource">jdbc/data</property>
<!-- property name="connection.driver_class">com.ibm.db2j.jdbc.DB2jDriver </property-->
<!-- property name="connection.url">jdbc:db2j:C:\DATA\data</property-->
<!-- dialect for DB2 -->
<property name="dialect">
org.hibernate.dialect.DB2Dialect
</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>

<mapping resource="toto/beans/Livre.hbm.xml" />

</session-factory>
</hibernate-configuration>

Struts Action file
------------------------
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {


//ActionForward forward = new ActionForward(); // return value
//ActionErrors errors = new ActionErrors();
Transaction tx =null;
Session session =null;

try {

LivreForm livreForm = (LivreForm) form;
SessionFactory sessionFactory= null ;

try {
Context ctx = new InitialContext();
Object obj = ctx.lookup("hibernate/SessionFactory");
sessionFactory = (SessionFactory) obj;
} catch (NamingException e1) {
e1.printStackTrace();
}

session = sessionFactory.openSession();
tx= session.beginTransaction();
Livre livre = new Livre();
livre.setCode(Integer.parseInt(livreForm.getCode()));
livre.setAuteur(livreForm.getAuteur());
livre.setTitre(livreForm.getTitre());
livre.setEdition(livreForm.getEdition());
livre.setAnnee(Integer.parseInt(livreForm.getAnnee()));
session.save(livre);
tx.commit();
}

catch (HibernateException e) {
e.printStackTrace();
tx.rollback();
return mapping.findForward("error");
}

finally{

// Actual contact insertion will happen at this step
session.flush();
session.close();
}
// If a message is required, save the specified key(s)
// into the request for use by the <struts:errors> tag.

/*if (!errors.isEmpty()) {
saveErrors(request, errors);
forward = mapping.findForward("error");
}
else {
forward = mapping.findForward("success");
}
// Finish with*/
return mapping.findForward("success");

}
}
My logs show the following error:

[07/03/06 17:45:07:967 GMT] 00000038 SystemErr R org.hibernate.exception.SQLGrammarException: could not get next sequence value
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:98)
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:534)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:522)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at strutstudio.actions.AjouterAction.execute(AjouterAction.java:61)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java(Compiled Code))
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java(Compiled Code))
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java(Compiled Code))
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:94)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Caused by: SQL Exception: Syntax error: Encountered "hibernate_sequence" at line 1, column 20.
at db2j.ai.j.generateCsSQLException(Unknown Source)
at db2j.ai.g.wrapInSQLException(Unknown Source)
at db2j.ai.g.handleException(Unknown Source)
at db2j.ai.c.handleException(Unknown Source)
at db2j.ai.e.handleException(Unknown Source)
at db2j.ai.p.<init>(Unknown Source)
at db2j.ax.e.<init>(Unknown Source)
at db2j.aw.b.<init>(Unknown Source)
at com.ibm.db2j.jdbc.EmbeddedDriver30.newLocalPreparedStatement(Unknown Source)
at db2j.ai.c._xs(Unknown Source)
at db2j.ai.c.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:123)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:73)
... 29 more



can you help me,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 8:47 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Check the sequence name in your Livre.hbm.xml , it will be wrong or it doesnt exist in DB


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.