-->
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.  [ 3 posts ] 
Author Message
 Post subject: Entity Manager Standalone - Java Persistence with Hibernate
PostPosted: Thu Oct 01, 2009 10:21 am 
Newbie

Joined: Thu Oct 01, 2009 10:11 am
Posts: 2
Hi newbie here, can anybody help me with this?

Here's my code:
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld");
         //getHelloWorldPersistenceProvider();
      
      EntityManager em = null;
      try {
         emf.createEntityManager();
      } catch (Exception e){
         e.printStackTrace();
      }


Persistence unit configuration file:
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
          version="1.0">
      <persistence-unit name="helloworld">
      <!-- needs only to be set if you use several jpa providers -->   
      <!-- <provider>org.hibernate.ejb.HibernatePersistence</provider> -->
      <!--  <class>org.hec.Message</class> -->
         <properties>
                <property name="hibernate.archive.autodetection" value="class, hbm"/>
                <property name="hibernate.show_sql" value="true"/>
             <property name="hibernate.format_sql" value="true"/>
             <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
             <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/Messages"/>
             <property name="hibernate.connection.username" value="hibernate_user"/>
             <property name="hibernate.connection.password" value="zoom"/>
             <property name="hibernate.c3p0.min_size" value="5"/>
             <property name="hibernate.c3p0.max_size" value="20"/>
             <property name="hibernate.c3p0.max_statements" value="50"/>
             <property name="hibernate.c3p0.timeout" value="300"/>
             <property name="hibernate.c3p0.idle_test_period" value="3000"/>
             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
             <!--  <property name="hibernate.hbm2ddl.auto" value="create"/> -->
          </properties>
   </persistence-unit>
</persistence>


stacktrace:
Code:
org.hibernate.TransactionException: Could not find UserTransaction in JNDI:
   at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:64)
   at org.hibernate.ejb.transaction.JoinableJTATransaction.<init>(JoinableJTATransaction.java:27)
   at org.hibernate.ejb.transaction.JoinableJTATransactionFactory.createTransaction(JoinableJTATransactionFactory.java:18)
   at org.hibernate.jdbc.JDBCContext.getTransaction(JDBCContext.java:186)
   at org.hibernate.impl.SessionImpl.getTransaction(SessionImpl.java:1282)
   at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:64)
   at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:34)
   at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:37)
   at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:32)
   at org.hec.TestHelloWorld.testEntityManager(TestHelloWorld.java:16)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
   at javax.naming.InitialContext.lookup(InitialContext.java:392)
   at org.hibernate.transaction.JTATransaction.<init>(JTATransaction.java:60)
   ... 31 more


Thanks in advance! :)


Top
 Profile  
 
 Post subject: Re: Entity Manager Standalone - Java Persistence with Hibernate
PostPosted: Thu Oct 01, 2009 10:38 am 
Newbie

Joined: Thu Oct 01, 2009 10:11 am
Posts: 2
Solved, seemed like library conflicts. Just copied the example's lib instead of figuring it out all by myself


Top
 Profile  
 
 Post subject: Re: Entity Manager Standalone - Java Persistence with Hibernate
PostPosted: Fri Oct 02, 2009 6:15 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Nice you solved it, but please use the correct forum: https://forum.hibernate.org/viewforum.php?f=1
this one is for "Search, Validator, Shards" only

_________________
Sanne
http://in.relation.to/


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