-->
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.  [ 1 post ] 
Author Message
 Post subject: Using Hibernate without persistence.xml
PostPosted: Fri Oct 09, 2009 5:57 pm 
Newbie

Joined: Fri Oct 09, 2009 5:00 pm
Posts: 1
I am new to Hibernate and am wondering whether there is any way to use it without the xml configuration file.

As far as I understood you can replace the mapping by using annotations, but is there a way, to declare the entities with the EntityManager programmatically?

I tried to modify the hellojpa example, but I always get an exception:
Code:
Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: hello.Message
   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:215)
   at hello.HelloWorld.main(HelloWorld.java:30)


Code:
System.getProperties().put("hibernate.connection.driver_class","org.apache.derby.jdbc.EmbeddedDriver");
System.getProperties().put("hibernate.connection.url","jdbc:derby:c:/tmp/database;create=true");
System.getProperties().put("hibernate.connection.username","");
System.getProperties().put("hibernate.c3p0.min_size","5");
System.getProperties().put("hibernate.c3p0.max_size","30");
System.getProperties().put("hibernate.c3p0.timeout","300");
System.getProperties().put("hibernate.c3p0.max_statements","50");
System.getProperties().put("hibernate.c3p0.idle_test_period","3000");      
System.getProperties().put("hibernate.dialect","org.hibernate.dialect.DerbyDialect");

EntityManagerFactory emf = Persistence.createEntityManagerFactory("helloworld");

EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();

Message message = new Message("Hello World with JPA");
em.persist(message);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.