-->
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.  [ 2 posts ] 
Author Message
 Post subject: overriding/customizing the table name for an entity.
PostPosted: Mon May 11, 2009 2:49 pm 
Newbie

Joined: Mon May 11, 2009 2:31 pm
Posts: 1
Hello,

I'm using JPA + Hibernate entity manager.

Is it possible to configure/customize/override the table name of an entity after the EntityManagerFactory is created? and how?

If not, how can I do that, for a JPA annotated class, before I build the EntityManagerFactory?

This is the code i'm using to build an EntityManagerFactory:
Code:
      Ejb3Configuration config = new Ejb3Configuration();
      config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
      config.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
      config.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:authdb");
      config.setProperty("hibernate.connection.username", "sa");
      config.setProperty("hibernate.connection.password", "");
      config.setProperty("hibernate.hbm2ddl.auto", "create-drop");
      //config.setProperty("hibernate.show_sql", "true");
      config.addAnnotatedClass(MyClass1.class);
      config.addAnnotatedClass(MyClass2.class);
      entityManagerFactory = config.buildEntityManagerFactory();


In the above example, MyClass2 is annotated with @Table(name = "xyz")
How can I override that name in the configuration?

Thanks,
I


Top
 Profile  
 
 Post subject: Re: overriding/customizing the table name for an entity.
PostPosted: Tue May 12, 2009 3:17 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I have no practical experience but it seems like a custom NamingStrategy is what you need. There is a brief section in the documentation about this: http://docs.jboss.org/hibernate/stable/ ... ategy.html

The example in the documentation only shows how to configure this with a 'Configuration' object. I don't know if it is possible with 'Ejb3Configuration'.


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