-->
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.  [ 13 posts ] 
Author Message
 Post subject: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 2:34 am 
Newbie

Joined: Mon May 18, 2009 4:51 am
Posts: 7
i need to add table at runtime to existing db schema
i made a business object java code generator
and i compiled this BO, and when i use this BO compiled, i got class not mapped
any one have an idea
thx.


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 5:31 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
use <prop key="hibernate.hbm2ddl.auto">create</prop> in your hibernate config file

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 5:44 am 
Newbie

Joined: Mon May 18, 2009 4:51 am
Posts: 7
thx for ur reply
do i need to add something in the code once i compile the new Business Object ?


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 6:21 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Only add auto to true in hibernate config file and run.

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 6:35 am 
Newbie

Joined: Mon May 18, 2009 4:51 am
Posts: 7
i did this and the DB are recreated

what i need is after i run the application i wnat to add a new Business object and use this BO at runtime without stopping the application recompile it


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 6:57 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
BO at runtime means what? Do you want to create an object(class) for newly created(at runtime) table without mapping file?

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 7:19 am 
Newbie

Joined: Mon May 18, 2009 4:51 am
Posts: 7
at runtime i create a table in the Database,
i generate a java Class corresponding on business object to a new table added , (annotation mapping is described into the Java Class )
and i compile this class;
and then i want to use this BO
so i got as error class not mapped.


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 8:25 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Please post your code and error message

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 9:48 am 
Newbie

Joined: Mon May 18, 2009 4:51 am
Posts: 7
at runtime the end user create a table in the DataBase Address_type
and in the server , i have a service that generate a Business object to the created new table [businness object' name = AddressType]

AnnotationConfiguration myConfiguration = new AnnotationConfiguration();

myConfiguration.setProperty("hibernate.dialect",
"it.roxana.tools.hibernate.MySQLDialect").setProperty(
"hibernate.connection.driver_class",
"com.mysql.jdbc.Driver").setProperty(
"hibernate.connection.username", "root").setProperty(
"hibernate.connection.password", "").setProperty(
"hibernate.connection.url",
"jdbc:mysql://localhost:3306/testDB?autoReconnect=true");

myConfiguration.addPackage("it.test.rc.model.bo");
hibSessionFactory = myConfiguration.configure("hibernate.cfg.xml")
.buildSessionFactory();

the hibSessionFactory definition is (in spring-data.xml )

<bean id="hibSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="it.test.rc.model" />
<property name="annotatedPackages">
<list>
<value>it.test.rc.model.bo</value>
</list>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">it.roxana.tools.hibernate.MySQLDialect</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
</props>
</property>
<property name="exposeTransactionAwareSessionFactory">
<value>false</value>
</property>
</bean>



finally i got the folowwing error

org.hibernate.hql.ast.QuerySyntaxException: AddressType is not mapped [SELECT adt.addressTypeId AS pk, adt.addressTypeName AS addressTypeName
FROM AddressType adt
]


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Tue Sep 29, 2009 9:49 am 
Newbie

Joined: Mon May 18, 2009 4:51 am
Posts: 7
for info, the new Business object generated is compiled by a java service
before i use the new BO


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Wed Sep 30, 2009 12:30 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Please use addAnnotatedClass() for adding class.

Code:
                  AnnotationConfiguration myConfiguration = new AnnotationConfiguration();

                  myConfiguration.addPackage("it.test.rc.model.bo");
                  try {
                        myConfiguration.addAnnotatedClass(Class.forName("it.test.rc.model.bo.generatedbo.AddressType")) ;
                  } catch (MappingException e) {
                        e.printStackTrace();
                  } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                  }

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Wed Sep 30, 2009 12:31 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
For your information

To add an annotated class to the configuration, you must call the addAnnotatedClass method with the Class of the class that you want to persist. (Yes, that's a great sentence to read aloud.) If you were unaware, you might instead try to call the addClass method that AnnotationConfiguration inherits from Configuration, and if you did, you would be mistaken because that method is looking for XML metadata in a classpath resource.

_________________
Thx,
Murugesan.
Web: http://www.murugesanpitchandi.com


Top
 Profile  
 
 Post subject: Re: Add table at runtime to existing db schema
PostPosted: Wed Sep 30, 2009 2:43 am 
Beginner
Beginner

Joined: Sat Aug 01, 2009 5:28 am
Posts: 42
i think u need to compile the code.once u have cretaed the new table ,add information to configuration and resources .without compiling that code its not possible

_________________
Warm Regards,
Tarun Walia


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