-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to get a Configuration without configfile?
PostPosted: Thu Jul 19, 2007 7:09 am 
Newbie

Joined: Thu Jul 19, 2007 6:38 am
Posts: 2
Hibernate version: 3.2.0.ga

Mapping documents: by annotations

Name and version of the database you are using: MySQL 5.0.27

Hello,

I have to use an openSessionInView-pattern (cause of freemarker and lazy loading).

My problem is how to get a org.hibernate.cfg.Configuration without using the hibernate.cfg.xml OR how I have to configure this file cause all my mappings are done by annotations inside the @Entity-classes and my datasources are defined in a *-ds.xml-file.


Thanks - Bastian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 10:17 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Code:
sessionFactory = new AnnotationConfiguration()
   .addPackage("test.animals") //the fully qualified package name
   .addAnnotatedClass(Flight.class)
   .addAnnotatedClass(Sky.class)
   .addAnnotatedClass(Person.class)
   .addAnnotatedClass(Dog.class)
   .addResource("test/animals/orm.xml")
   .buildSessionFactory();


Chapter 1 of the manual!

http://hibernate.org/hib_docs/annotatio ... figuration

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 10:41 am 
Newbie

Joined: Thu Jul 19, 2007 6:38 am
Posts: 2
cbredesen wrote:
Code:
sessionFactory = new AnnotationConfiguration()
   .addPackage("test.animals") //the fully qualified package name
   .addAnnotatedClass(Flight.class)
   .addAnnotatedClass(Sky.class)
   .addAnnotatedClass(Person.class)
   .addAnnotatedClass(Dog.class)
   .addResource("test/animals/orm.xml")
   .buildSessionFactory();


Chapter 1 of the manual!

http://hibernate.org/hib_docs/annotatio ... figuration


Thanks for the reply.
But my question was how to get a Configuration without considering the Entity classes.

If I use addAnnotatedClass(...) I destroy the single-point-of-truth. It is not useable to add all entities manually.

Is it possible that the configuration looks itself for all annotated classes?

sessionFactory = new AnnotationConfiguration().buildSessionFactory(); does not work.
Code:
org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
....

I want to get the datasource from the *-ds.xml file.

Bastian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 10:08 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
1. If your persistence.xml is in META-INF of the package that you're deploying from (the one containing your entities), it will pick up all annotated classes. Just don't set the "exclude-unlisted-classes" option. I would recommend creating a JAR with the entities and persistence.xml as a unit....

2. Dialect is not DataSource. You must tell Hibernate which Dialect to use in your database.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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