-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate transaction can not work in the struts.action?
PostPosted: Fri Nov 28, 2003 9:34 am 
Newbie

Joined: Fri Nov 28, 2003 9:04 am
Posts: 4
Location: China
Hi everyone:

I write some insert data transaction code into the action class of strue.
But the jsp page throw these Errors.

my application server is : Tomcat 5.0
my database is MySQL
and also using struts 1.1.

java.lang.NoClassDefFoundError: javax/transaction/Synchronization
net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:310)
net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:323)
net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:331)
org.greenpinaster.hr.action.EmpAction.beginTransaction(Unknown Source)
org.greenpinaster.hr.action.EmpAction.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

my hibernate.cfg.xml file:
<session-factory name="hibernate/SessionFactory">
<!-- properties -->
<property name="connection.datasource">java:comp/env/jdbc/greenpinaster</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<!-- mapping files -->
<mapping resource="employee.hbm.xml"/>
</session-factory>

Information in Tomcat console :
信息: JNDI InitialContext properties:{}
2003-11-28 21:22:12 net.sf.hibernate.connection.DatasourceConnectionProvider configure
信息: Using datasource: java:comp/env/jdbc/greenpinaster
2003-11-28 21:22:12 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
信息: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended
2003-11-28 21:22:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Use scrollable result sets: true
2003-11-28 21:22:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: JDBC 2 max batch size: 15
2003-11-28 21:22:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: Query language substitutions: {}
2003-11-28 21:22:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
信息: cache provider: net.sf.hibernate.cache.JCSCacheProvider
2003-11-28 21:22:12 net.sf.hibernate.cfg.Configuration configureCaches
信息: instantiating and configuring caches
2003-11-28 21:22:13 net.sf.hibernate.impl.SessionFactoryImpl <init>
信息: building session factory
2003-11-28 21:22:14 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
信息: Factory name: hibernate/SessionFactory
2003-11-28 21:22:14 net.sf.hibernate.util.NamingHelper getInitialContext
信息: JNDI InitialContext properties:{}
2003-11-28 21:22:14 net.sf.hibernate.util.NamingHelper bind
信息: Creating subcontext: hibernate
2003-11-28 21:22:14 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
信息(Information): Bound factory to JNDI name: hibernate/SessionFactory
2003-11-28 21:22:14 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
Warning: InitialContext did not implement EventContext

I have no ideal about that errors.
Please somebody help me.
Thanks a lot.

_________________
hai , enjoy everyday


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 9:38 am 
Newbie

Joined: Fri Nov 28, 2003 9:04 am
Posts: 4
Location: China
my server.xml :
...
<Context path="/greenpinaster" docBase="greenpinaster">
<Resource name="jdbc/greenpinaster" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/greenpinaster">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- DBCP database connection settings -->
<parameter>
<name>url</name>
<value>jdbc:mysql:///greenpinaster</value>
</parameter>
<parameter>
<name>driverClassName</name><value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>***</value>
</parameter>
<parameter>
<name>password</name>
<value>***</value>
</parameter>

<!-- DBCP connection pooling options -->
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>

</ResourceParams>
</Context>
...

web.xml:
...
<resource-env-ref>
<description>
Session factory for SessionBean instances.
</description>
<resource-env-ref-name>
hibernate/SessionFactory
</resource-env-ref-name>
<resource-env-ref-type>
net.sf.hibernate.SessionFactory
</resource-env-ref-type>
<res-auth>Container</res-auth>
</resource-env-ref>
...

_________________
hai , enjoy everyday


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You don't have the jar with javax.transaction.synchronization in your classpath!

I'ts named jta.jar.

p.s. RTFJBGFCM! ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Strongly recommend against modifying server.xml for JNDI!
PostPosted: Fri Nov 28, 2003 8:12 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I've read your example server.xml and web.xml entries and I STRONGLY advise against modifying your server.xml and web.xml that way. I tried that under Tomcat and couldn't get it to work. I did find a very easy alternative solution. As long as your application creates the configuration, the SessionFactory can be automatically stored in the JNDI context.

You have to use a hibernate.cfg.xml file (I think there is an equivalent hibernate.properties entry but I don't recall it off-hand since I prefer to use a hibernate.cfg.xml file) and use a session-factory tag like so:

<session-factory name="SOMEJNDIURL">
...
</session-factory>

I use dgf:hibernate/SessionFactory and when I create my configuration, it is automatically put into that content (created automatically if it isn't there) by Hibernate. It worked in v2.0.3 and v2.1beta6 for me under tomcat v4.1.24 (and .27 and .29).

I have other posts that detail it plus give examples on how to retrieve it via example JNDI calls.

Regards,
David


Top
 Profile  
 
 Post subject: Forgot to mention, I use it under Struts v1.0 & v1.1 :)
PostPosted: Fri Nov 28, 2003 8:16 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I'm using Hibernate (both v2.0.3 and v2.1beta6) with Struts (v1.0 and v1.1) without any problems. My configuration includes some transactions, cached queries, cached objects, named parameters, database pooling (DBCP), JNDI binding, facades to hide hibernate from the session, etc. No trouble so far. :)

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2003 11:10 pm 
Newbie

Joined: Fri Nov 28, 2003 9:04 am
Posts: 4
Location: China
I added the jta package into my appliction library .And adjusted my server.xml amd web.xml.
It's works very well.

^_^

Thanks a billion for your help.

_________________
hai , enjoy everyday


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