-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to do "schemaupdate" with EJB3.0?
PostPosted: Fri Nov 24, 2006 12:45 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
Now that I use EJB3.0 annotations embedded in my source codes, I do not have .hbm.xml files. How can I update database schema without providing .hbm.xml files?

In the past I was using Hibernate with .hbm.xml files generated by XDoclet. When I needed to update database schema, the following code worked fine since I listed mapping information i.e. .hbm.xml(s) in hibernate.cfg.xml.

Code:
public static void initialization()
{
  System.out.println("initialization");

   Configuration cfg = new Configuration();
   cfg.configure("hibernate.cfg.xml");
   
   SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
   schemaUpdate.execute(true, true);
}


As I do not have .hbm.xml files any more (they were replaced with EJB3.0 annotations), this code does not work. Please help me understand how to update database schema without having hbm.xml files. I appreciate your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 8:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that code still works perfectly fine if you just use the AnnotationConfiguration that is created by you or the entitymanager.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: How to do "schemaupdate" with EJB3.0?
PostPosted: Fri Nov 24, 2006 12:33 pm 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
Max, thank you for your reply. Could you elaborate how to create AnnotationConfiguration from an EntityManager? I wrote the code like below but it did not work:

Code:
public static void initialization()
{
    Ejb3Configuration ejb3cfg = new Ejb3Configuration();
    AnnotationConfiguration cfg = ejb3cfg.getHibernateConfiguration();

    SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
    schemaUpdate.execute(true, true);
}


I do not have "hibernate.cfg.xml" since I use "persistence.xml" with EJB3.0.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 24, 2006 12:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
look in entitymanager docs on how to get access to hibernate specific functionallity.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: schemaupdate" with EJB3.0?
PostPosted: Fri Nov 24, 2006 7:45 pm 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
max, I read EntityManager doc (hibernate_entitymanager.pdf) to write the code above. That's how I found, "ejb3cfg.getHibernateConfiguration()" to accesse to hibernate specific feature. I do not understand what's worng with the code.

Could you tell mw which EntityManager API can get me back an AnnotationConfiguration? Or, could you tell me which keyword I should use to search on EntityManager doc?

The key word, "AnnotationConfiguration" was not found in the doc. "hibernate specific" had four entries but what I found was "ejb3cfg.getHibernateConfiguration()".


Top
 Profile  
 
 Post subject: Re: schemaupdate" with EJB3.0?
PostPosted: Sat Nov 25, 2006 10:51 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
Thanks, max. I finally found the following code works :-)

Code:
public static void initialization()
{
    Ejb3Configuration ejb3cfg = new Ejb3Configuration();
    AnnotationConfiguration cfg = ejb3cfg.getHibernateConfiguration();
    cfg.configure("hibernate.cfg.xml");

    SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
    schemaUpdate.execute(true, true);   
}


Since I deployed "persistence.xml" as an EJB3.0 configuration file, I thought I did not have to provide "hibernate.cfg.xml". However, if I want to do "schemaupdate", it seems I have to manually provide "hibernate.cfg.xml" and list all <mapping class = "some.class.name"/> in it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 25, 2006 11:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can use ejb3cfg.configure(punitname, mapwithsettings) to get autoscan.

see http://opensource.atlassian.com/project ... se/EJB-154

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: How to do "schemaupdate" with EJB3.0?
PostPosted: Sat Nov 25, 2006 11:38 am 
Newbie

Joined: Sun Feb 05, 2006 7:46 pm
Posts: 18
Gee! This is beautiful. This is a great feature. The following code works beautifully:

Code:
public static void initialization()
{
    Ejb3Configuration ejb3cfg = new Ejb3Configuration().configure("myPersistenceUnitName", null);
    AnnotationConfiguration cfg = ejb3cfg.getHibernateConfiguration();

   SchemaUpdate schemaUpdate = new SchemaUpdate(cfg);
   schemaUpdate.execute(true, true);
}

Max, I appreciate your help and patience.


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