-->
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.  [ 3 posts ] 
Author Message
 Post subject: Running "Getting Started" examples with Maven??? H
PostPosted: Sat Jul 09, 2005 4:11 pm 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:55 pm
Posts: 37
Hello,

I am trying to build the "eg" examples under Maven 1.0.2. Maven is much stricter when it comes to the dependencies and I am finding myself guessing which version Hibernate is using and what libraries are actually required for the eg examples...

Anyone managed to build (and RUN) the eg example under a simple maven jar?

Could you post your Dependencies?
Did you have to change any code?
Did you manage to CREATE the DB schema (looks like removing the FK is failing and everything from there on...)

I have reached the point where it does compile and connects to the database (MySQL) but it does not seem to be able to generate the schema! See the difference between the ANT run and the MAVEN run:

Many thanks!

ANT:
Code:
     [java] 20:17:36,377  INFO Configuration:917 - processing foreign key constraints
     [java] 20:17:36,498  INFO SchemaExport:113 - Running hbm2ddl schema export
     [java] 20:17:36,508  INFO SchemaExport:129 - exporting generated schema to database
     [java] 20:17:36,518  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
     [java] 20:17:36,518  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
     [java] 20:17:36,518  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
     [java] 20:17:36,518  INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql:///testhibernate
     [java] 20:17:36,518  INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
     [java] 20:17:36,628 DEBUG SchemaExport:143 - alter table AuctionItem drop foreign key FK522A9BD61107FE9B
     [java] 20:17:36,818 DEBUG SchemaExport:143 - alter table AuctionItem drop foreign key FK522A9BD6F65B1FAF
     [java] 20:17:36,988 DEBUG SchemaExport:143 - alter table Bid drop foreign key FK104DDEE6E7E98
     [java] 20:17:37,189 DEBUG SchemaExport:143 - alter table Bid drop foreign key FK104DDF43A3910
     [java] 20:17:37,369 DEBUG SchemaExport:143 - drop table if exists AuctionItem
     [java] 20:17:37,399 DEBUG SchemaExport:143 - drop table if exists AuctionUser
     [java] 20:17:37,439 DEBUG SchemaExport:143 - drop table if exists Bid
     [java] 20:17:37,479 DEBUG SchemaExport:161 - create table AuctionItem (
     [java]     id bigint not null auto_increment,
     [java]     seller bigint not null,
     [java]     description varchar(200) not null,
     [java]     ends datetime,
     [java]     condition integer,
     [java]     successfulBid bigint,
     [java]     primary key (id),
     [java]     unique (seller, description)
     [java] ) comment 'An item that is being auctioned.' type=InnoDB
     [java] 20:17:37,629 DEBUG SchemaExport:161 - create table AuctionUser (


MAVEN
Code:
20:52:41,474  INFO Configuration:917 - processing foreign key constraints
20:52:41,484  INFO SchemaExport:113 - Running hbm2ddl schema export
20:52:41,494  INFO SchemaExport:129 - exporting generated schema to database
20:52:41,504  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
20:52:41,504  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
20:52:41,514  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
20:52:41,524  INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql:///testhibernate
20:52:41,535  INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
20:52:41,585 DEBUG SchemaExport:143 - alter table AuctionItem drop foreign key FK522A9BD651F579EE
20:52:41,855 DEBUG SchemaExport:149 - *******Unsuccessful: alter table AuctionItem drop foreign key FK522A9BD651F579EE*******
20:52:41,855 DEBUG SchemaExport:150 - *******Error on rename of '.\testhibernate\auctionitem' to '.\testhibernate\#sql2-314-48' (errno: 152)*******
20:52:41,865 DEBUG SchemaExport:143 - alter table AuctionItem drop foreign key FK522A9BD68F76DFC
20:52:42,015 DEBUG SchemaExport:149 - *******Unsuccessful: alter table AuctionItem drop foreign key FK522A9BD68F76DFC*******
20:52:42,015 DEBUG SchemaExport:150 - *******Error on rename of '.\testhibernate\auctionitem' to '.\testhibernate\#sql2-314-48' (errno: 152)*******
20:52:42,025 DEBUG SchemaExport:143 - alter table Bid drop foreign key FK104DD17722FE5
20:52:42,185 DEBUG SchemaExport:149 - *******Unsuccessful: alter table Bid drop foreign key FK104DD17722FE5*******
20:52:42,185 DEBUG SchemaExport:150 - *******Error on rename of '.\testhibernate\bid' to '.\testhibernate\#sql2-314-48' (errno: 152)*******
20:52:42,195 DEBUG SchemaExport:143 - alter table Bid drop foreign key FK104DD3527B463
20:52:42,346 DEBUG SchemaExport:149 - *******Unsuccessful: alter table Bid drop foreign key FK104DD3527B463*******
20:52:42,356 DEBUG SchemaExport:150 - *******Error on rename of '.\testhibernate\bid' to '.\testhibernate\#sql2-314-48' (errno: 152)*******
20:52:42,366 DEBUG SchemaExport:143 - drop table if exists AuctionItem
20:52:42,376 DEBUG SchemaExport:149 - *******Unsuccessful: drop table if exists AuctionItem*******
20:52:42,376 DEBUG SchemaExport:150 - *******Cannot delete or update a parent row: a foreign key constraint fails*******
20:52:42,386 DEBUG SchemaExport:143 - drop table if exists AuctionUser
20:52:42,396 DEBUG SchemaExport:149 - *******Unsuccessful: drop table if exists AuctionUser*******
20:52:42,406 DEBUG SchemaExport:150 - *******Cannot delete or update a parent row: a foreign key constraint fails*******
20:52:42,416 DEBUG SchemaExport:143 - drop table if exists Bid
20:52:42,426 DEBUG SchemaExport:149 - *******Unsuccessful: drop table if exists Bid*******
20:52:42,436 DEBUG SchemaExport:150 - *******Cannot delete or update a parent row: a foreign key constraint fails*******
20:52:42,446 DEBUG SchemaExport:161 - create table AuctionItem (
    id bigint not null auto_increment,
    seller bigint not null,
    description varchar(200) not null,
    ends datetime,
    condition integer,
    successfulBid bigint,
    primary key (id),
    unique (seller, description)
) comment 'An item that is being auctioned.' type=InnoDB
20:52:42,536 ERROR SchemaExport:167 - *******Unsuccessful: create table AuctionItem (id bigint not null auto_increment, seller bigint not null, description v
archar(200) not null, ends datetime, condition integer, successfulBid bigint, primary key (id), unique (seller, description)) comment 'An item that is
being auctioned.' type=InnoDB*******
20:52:42,556 ERROR SchemaExport:168 - *******Table 'auctionitem' already exists*******
20:52:42,566 DEBUG SchemaExport:161 - create table AuctionUser (


Here is my set of dependencies (probably OTT and may be wrong???)
Code:
  <dependencies>
    <dependency>
      <groupId>hibernate</groupId>
      <artifactId>hibernate</artifactId>
      <version>3.0.5</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>hibernate</groupId>
      <artifactId>hibernate-tools</artifactId>
      <version>2.1.3</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant</artifactId>
      <version>1.6.5</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>antlr</groupId>
      <artifactId>antlr</artifactId>
      <version>2.7.2</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib</artifactId>
      <version>2.1</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>asm</groupId>
      <artifactId>asm</artifactId>
      <version>1.5.3</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>asm</groupId>
      <artifactId>asm-attrs</artifactId>
      <version>1.5.3</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-jelly</groupId>
      <artifactId>commons-jelly</artifactId>
      <version>1.0-beta-4</version>
      <url>http://jakarta.apache.org/commons/jelly/</url>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-beanutils</groupId>
      <artifactId>commons-beanutils</artifactId>
      <version>1.7.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-betwixt</groupId>
      <artifactId>commons-betwixt</artifactId>
      <version>1.0-alpha-1</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.2</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-digester</groupId>
      <artifactId>commons-digester</artifactId>
      <version>1.5</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>2.1.1</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.0.4</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
      <version>1.2</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.9</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>xml-apis</groupId>
      <artifactId>xml-apis</artifactId>
      <version>1.0.b2</version>
      <url>http://xml.apache.org/xerces2-j/</url>
    </dependency>
    <dependency>
      <groupId>xerces</groupId>
      <artifactId>xercesImpl</artifactId>
      <version>2.6.2</version>
      <url>http://xml.apache.org/xerces2-j/</url>
    </dependency>
    <dependency>
      <groupId>odmg</groupId>
      <artifactId>odmg</artifactId>
      <version>3.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib</artifactId>
      <version>2.1</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>1.6</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>jdom</groupId>
      <artifactId>jdom</artifactId>
      <version>1.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>1.1</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>jta</groupId>
      <artifactId>jta</artifactId>
      <version>1.0</version>
      <type>jar</type>
    </dependency>
    <dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>3.1.10</version>
     <type>jar</type>
    </dependency>
  </dependencies>


Hibernate version: 3.0.5

Mapping documents: as per "Getting Started" examples

Code between sessionFactory.openSession() and session.close():
Code:
Configuration cfg = new Configuration().addClass(AuctionItem.class)
     .addClass(Bid.class).addClass(User.class).setProperty(
         Environment.HBM2DDL_AUTO, "create");


Full stack trace of any exception that occurs:
see above.

Name and version of the database you are using:
MySQL 4.1 (works under Ant)

The generated SQL (show_sql=true):
see above

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: more info on this issue:FK name does not exists under Maven!
PostPosted: Sun Jul 10, 2005 7:39 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:55 pm
Posts: 37
Hello

The error (errno 152) comes from MySQL and it looks that it may be reported incorrectly (http://bugs.mysql.com/bug.php?id=10333)

However, the issue looks like Hibernate is trying to drop a foreign key that does not exist under Maven (the tables already exist after the "ant eg").

Under Ant:
Code:
alter table AuctionItem drop foreign key FK522A9BD61107FE9B
alter table AuctionItem drop foreign key FK522A9BD6F65B1FAF
alter table Bid drop foreign key FK104DDEE6E7E98
alter table Bid drop foreign key FK104DDF43A3910


Under Maven:
Code:
alter table AuctionItem drop foreign key FK522A9BD651F579EE
Unsuccessful: alter table AuctionItem drop foreign key FK522A9BD651F579EE
Error on rename of '.\testhibernate\auctionitem' to '.\testhibernate\#sql2-6dc-2' (errno: 152)
alter table AuctionItem drop foreign key FK522A9BD68F76DFC
Unsuccessful: alter table AuctionItem drop foreign key FK522A9BD68F76DFC
Error on rename of '.\testhibernate\auctionitem' to '.\testhibernate\#sql2-6dc-2' (errno: 152)
alter table Bid drop foreign key FK104DD17722FE5
Unsuccessful: alter table Bid drop foreign key FK104DD17722FE5
Error on rename of '.\testhibernate\bid' to '.\testhibernate\#sql2-6dc-2' (errno: 152)
alter table Bid drop foreign key FK104DD3527B463
Unsuccessful: alter table Bid drop foreign key FK104DD3527B463
Error on rename of '.\testhibernate\bid' to '.\testhibernate\#sql2-6dc-2' (errno: 152)


The foreign key names are different!!!

How does Hibernate name its foreign keys, why would it be differrent under Maven... Is it due to a library/dependency?

Both are using jdk 1.5...

So, please, please could someone who has managed to build some Hibernate 3.0.5 stuff under maven post his/her dependencies...
many thanks!

regards from a sunny London,

Benoit


Top
 Profile  
 
 Post subject: ant eg and maven "eg" generated different FK names
PostPosted: Mon Jul 11, 2005 7:50 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:55 pm
Posts: 37
Got to the bottom of this... sort of...

I did run "ant eg" and it created the model ok.
When I moved to Maven, I ran exactly the same example but during the creation of the model, Hibernate tries to drop the foreign key by names and for some reason, under Maven it generated a different name.

So it could not drop the FK and hence could not rebuild the DB and encountered some duplicate rows.

This still does not explain how the FK names could be different...

I can only assume that the dependencies that I had to guess pulled a different library that generate a different FK name...

Could someone post their Maven dependencies for Hibernate 3.0.5?

many thanks

Benoit


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