-->
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.  [ 9 posts ] 
Author Message
 Post subject: Annotation and schema export
PostPosted: Tue Jun 23, 2009 10:43 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
Hi there

I used hyperjaxb2 which generated my classes (from a XSD) and the appropriate *.hbm.xml files. With the schemaexport ant task, I could directly generate AND execute the sql statement.

Now I'm using hyperjaxb which supports hibernate3 annotations. From the XSD, the annotated classes and a "persistence.xml" are generated. The problems are now the following:

  • I have to manually enter the classes I like to export in the hibernat.cfg.xml (like <mapping class="com.example.Class"/>). But as the classes are generated, I don't want to update this file manually.
  • When I define the mapped classes manually, the schema is exported to a file, but not to the database as I had it with hibernate2's schemaexport.

Thats my schemaexport task, should be very common:
Code:
  <target name="export.database.schema">
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="schemaexport.lib.path" />
    <hibernatetool destdir="${dir.sources.generated}">
      <annotationconfiguration configurationfile="hibernate.cfg.xml" />
      <hbm2ddl drop="true" create="true" export="true" outputfilename="schema.sql" delimiter=";" format="true" />
    </hibernatetool>
  </target>


How do I get the same build process as before?
I feel like I had googled the whole internet without finding what I want. please help me out.


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Thu Jun 25, 2009 3:01 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
1th push :-)


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Mon Jun 29, 2009 2:25 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
2nd push.

Am I alone with this problem, or is there no solution?


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Mon Jun 29, 2009 3:29 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
seems as you have a generated "persistence.xml" file you could maybe switch to a jpaconfiguration like so:

Code:
<jpaconfiguration persistenceunit="<pu_name>"/>
   <hbm2ddl export="false" format="true" outputfilename="schema.sql"/>


Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Mon Jun 29, 2009 7:42 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
Thanks, that's what I was looking for.

Unfortunately, I can't get it working.

Code:
export.database.schema:
[hibernatetool] Executing Hibernate Tool with a JPA Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] An exception occurred while running exporter #2:hbm2ddl (Generates database schema)
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.

BUILD FAILED
~\-build.xml:71: org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.

Total time: 1 second


I tried some possibilities. Setting the properties in the persistence.xml:

Code:
    <properties>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
      <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db" />
      <property name="hibernate.connection.username" value="user" />
      <property name="hibernate.connection.password" value="password" />
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
      <property name="hibernate.show_sql" value="true" />
    </properties>

.. the same as properties in the hibernate.properties. Nothing worked.

I don't know whether my persistence.xml is found or not: I deleted it, and I get still the same error. But if I set the following:
Code:
       <jpaconfiguration persistenceunit="anything.that.doesnt.exist"  />

I get the error
Code:
Persistence unit not found: 'anything.that.doesnt.exist'.

So it must be finding something. Is it just the package? It seems like it doesn't load my persistence.xml.


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Mon Jun 29, 2009 8:26 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
As far as I can remember I had this issue when I first tried to use HibernateTools, I think I fixed it by placing the persistence.xml file in <src>/META-INF/

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Thu Jul 02, 2009 8:49 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
I also put it there, but without success :-( I really don't know how or where to get a solution for this problem.


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Thu Jul 02, 2009 10:17 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
I just solved the problem half-way.

If I use another persistence-unit-name than the package name (com.example.myapp), it works!
Now I really wonder where it gets the "com.telekurs.mincoll" persistence-unit. I just know it's not my persistence.xml...


Top
 Profile  
 
 Post subject: Re: Annotation and schema export
PostPosted: Thu Jul 02, 2009 10:56 am 
Newbie

Joined: Tue Jun 23, 2009 9:56 am
Posts: 7
Location: Switzerland, Zürich
I could isolate the problem a bit more:

This fails (blabla dialect not set):

build.xml
Code:
//...
<xjc destdir="${dir.sources.generated}" extension="true">
         <arg line="
        -Xhyperjaxb3-ejb
        -XtoString
        -Xhyperjaxb3-ejb-persistenceUnitName=myPersistenceUnitName" />
// ...
<jpaconfiguration persistenceunit="myPersistenceUnitName"  />

/META-INF/persistence.xml
Code:
// ...
    <persistence-unit name="myPersistenceUnitName">
// ...

even though everything should work correctly! Because if I change the persistenceUnitName manually like so:

build.xml
Code:
<jpaconfiguration persistenceunit="anythingelse"  />

persistence.xml
Code:
// ...
    <persistence-unit name="anythingelse">
// ...


It works! I searched for "myPersistenceUnitName" in all files, but it's only found in the build.xml and persistence.xml. How come??

Edit: Maybe I should open a bug report as this doesn't seem to be in the scope of hibernate.


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