• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to Create Auto Schema

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a package which contains all entity beans and then corresponding persistence.xml file..when I deploy EAR file in JBOSS..its not creating the schema automatically..is there any way to achieve this.

Thanks in Advance,


Best Regards,
Rajasekhar.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This depends on which JPA provider you are using. The JPA does not define auto schema creation.

For EclipseLink you set the persistence.xml property,

"eclipselink.ddl-generation"="create-tables"
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Sutherland wrote:This depends on which JPA provider you are using. The JPA does not define auto schema creation.

For EclipseLink you set the persistence.xml property,

"eclipselink.ddl-generation"="create-tables"



actually I am using Hibernate and JPA

here is my persistence.xml file:


<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="DefaultDS" transaction-type="JTA">

<jta-data-source>java:/DefaultDS</jta-data-source>

<class>com.ernst.persistenceImpl.beanImpl.ArtikelBean</class>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/lagerstandnew"/>

<property name="hibernate.connection.username" value="raja"/>
<property name="hibernate.connection.password" value="sekhar"/>

<!-- Scan for annotated classes and Hibernate mapping XML files -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.transaction.factory_class"
value="org.hibernate.transaction.JDBCTransactionFactory"/>
<!-- SQL stdout logging -->
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
</properties>
</persistence-unit>
</persistence>



but its not generating any autoschema..can you please tell me whats going wrong with it.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try changing...

To...


See if that helps...
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imran Perwez wrote:Try changing...

To...


See if that helps...



If I use above code also its not generating any tables..

what I found one interesting fact is..when jboss runs persistence.xml its not generating any create table queries..thats why its not creating any tables..how to generate the create table queries automatically.
 
Imran Perwez
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe a silly question... but I take it you are using JPA entities that are correctly annotated? And, not the old style EJB2.1 entity bean?

I don't have the issue you have. I have quite a minimalistic persistence.xml file and datasource compared to yours...

peristence.xml...



Datasource in "<jboss>\server\default\deploy"...

 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imran Perwez wrote:Maybe a silly question... but I take it you are using JPA entities that are correctly annotated? And, not the old style EJB2.1 entity bean?

I don't have the issue you have. I have quite a minimalistic persistence.xml file and datasource compared to yours...

peristence.xml...



Datasource in "<jboss>\server\default\deploy"...



actually I am using almost similar specifications made by you..I will tell one more interesting thing..its creating tables automatically when I have *.hbm.xml files but when I dont have these xml files its not creating any tables directly by using entity beans..I dont want to create hibernate matching files..jboss have to create tables just by using my entity tables only..is it possible to do this?
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for your quick view this is my entity bean..can you please check it whats going wrong in it.

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


for your quick view this is my entity bean


Entity Beans are an EJB 2 technology. It confuses the issue if you use the term to refer to JPA classes.
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:


for your quick view this is my entity bean


Entity Beans are an EJB 2 technology. It confuses the issue if you use the term to refer to JPA classes.



can you please tell me how can I create the table using above class.
 
Imran Perwez
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's your transaction strategy that is causing the problem



Have you tried using a different transaction strategy?

 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imran Perwez wrote:I think it's your transaction strategy that is causing the problem



Have you tried using a different transaction strategy?



I have tried with other transaction factories also..but it will throw classcast exception for it.
 
Imran Perwez
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What was the exception?...
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Transactions are unlikely to be the problem I think - DDL is (usually) not transactional.

Your configuration refers to something called ArtikelBean, which is not your annotated class. My guess is ArtikelBean does not contain annotations hbm2ddl can use. Can we see the class ArtikelBean, if that is indeed what you are trying to map? I see you have hibernate.archive.autodetection set too, could it be your mapped class is not deployed where you think it is? For auto detection to work, you need to have things packaged pretty much as the specification defines them. Where do you deploy persistence.xml to?
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imran Perwez wrote:What was the exception?...



java.lang.ClassCastException: org.hibernate.transaction.TransactionFactoryFactor
y cannot be cast to org.hibernate.transaction.TransactionFactory
at org.hibernate.transaction.TransactionFactoryFactory.buildTransactionF
actory(TransactionFactoryFactory.java:65)
at org.hibernate.cfg.SettingsFactory.createTransactionFactory(SettingsFa
ctory.java:452)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:
165)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101
)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1325)

but it will not throw any error by using JTATransactionFactory, but the result is same.
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:Transactions are unlikely to be the problem I think - DDL is (usually) not transactional.

Your configuration refers to something called ArtikelBean, which is not your annotated class. My guess is ArtikelBean does not contain annotations hbm2ddl can use. Can we see the class ArtikelBean, if that is indeed what you are trying to map? I see you have hibernate.archive.autodetection set too, could it be your mapped class is not deployed where you think it is?




hi..later I have replaced the above bean with NrKreiseBean which was pasted in above comment..may be its also a issue..can you please check the above code annotations one more time..its working with hbm.xml file but not with annotated class..can you please look it.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess is you are either using an old version of persistence.xml. Hibernate seems to be reporting it creates a schema without any exceptions occurring, which makes me think your annotated class is not being found.
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:My guess is you are either using an old version of persistence.xml. Hibernate seems to be reporting it creates a schema without any exceptions occurring, which makes me think your annotated class is not being found.



I am using this version:


<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="LagerstandnewDS" transaction-type="JTA">

<jta-data-source>java:/LagerstandnewDS</jta-data-source>

<class>com.ernst.persistenceImpl.beanImpl.NrKreiseBean</class>

<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/lagerstandnew;create=true"/>
<property name="javax.persistence.jdbc.user" value="raja"/>
<property name="javax.persistence.jdbc.password" value="sekhar"/> -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/lagerstandnew"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="sekhar"/>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>

</properties>

</persistence-unit>
</persistence>


 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that valid XML? You have a trailing comment.
 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:Is that valid XML? You have a trailing comment.



I hope its a valid xml..because if there is any error in xml normally parser will throw the error...what do you think.
 
Imran Perwez
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This bit, end of line...

 
rajasekhar kannamaneni
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imran Perwez wrote:This bit, end of line...



hi, this is my actual xml code and above is due to my mistake while pasting it here.

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="LagerstandnewDS" transaction-type="JTA">

<jta-data-source>java:/LagerstandnewDS</jta-data-source>

<class>com.ernst.persistenceImpl.beanImpl.NrKreiseBean</class>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/lagerstandnew"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="sekhar"/>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>

<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.use_structured_entries" value="true"/>

<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="use_sql_comments" value="true"/>
</properties>

</persistence-unit>
</persistence>

 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic