-->
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: SchemaExport sql-type problem
PostPosted: Wed Oct 12, 2005 1:18 am 
Newbie

Joined: Tue Oct 11, 2005 8:38 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Hibernate 3.0.5
Mapping documents:
<hibernate-mapping>
<class name="A" table="a" >
<id name="id" unsaved-value="null">
<generator class="assigned"/>
</id>
<many-to-one
name="b" class="B" not-null="true" unique="true" />
...

<hibernate-mapping>
<class name="B" table="b" >
<id name="bb" unsaved-value="null">
<column name="bb" length="12" sql-type="char(12)" not-null="true"/>
<generator class="assigned"/>
</id>
...

Code between sessionFactory.openSession() and session.close():
Configuration cc = new Configuration();
cc.configure();
new SchemaExport(cc).create(false, true);
Full stack trace of any exception that occurs:
2005-10-11 13:49:43,906 ERROR SchemaExport:167 - Unsuccessful: alter table a add constraint FK17E3CD0A98C01 foreign key (b) references b
2005-10-11 13:49:43,906 ERROR SchemaExport:168 - Column 'b.bb' is not the same data type as referencing column 'a.b' in foreign key 'FK17E3CD0A98C01'.

Name and version of the database you are using:
ms sql 2000 sp4
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
2005-10-11 13:18:58,875 DEBUG SchemaExport:161 - alter table a
add constraint FK17E3CD0A98C01
foreign key (b)
references b
2005-10-11 13:18:58,921 DEBUG NewPooledConnection:304 - com.mchange.v2.c3p0.impl.NewPooledConnection@1551b0 handling a throwable.
java.sql.SQLException: Column 'b.bb' is not the same data type as referencing column 'a.b' in foreign key 'FK17E3CD0A98C01'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:620)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:483)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:445)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:623)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:1042)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:999)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:64)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:163)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:99)
at AppMain.databaseSchemaOlustur(AppMain.java:117)
at AppMain.main(AppMain.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
2005-10-11 13:18:58,921 DEBUG SqlUtils:83 - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: S1000; errorCode: 1778]
java.sql.SQLException: Column 'b.bb' is not the same data type as referencing column 'a.b' in foreign key 'FK17E3CD0A98C01'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:620)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:483)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:445)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:623)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:1042)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:999)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:64)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:163)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:99)
at AppMain.databaseSchemaOlustur(AppMain.java:117)
at AppMain.main(AppMain.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
2005-10-11 13:18:58,921 DEBUG SqlUtils:87 - Nested SQLException or SQLWarning:
java.sql.SQLException: Could not create constraint. See previous errors.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:625)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:483)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:445)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:623)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:1042)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:999)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:64)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:163)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:99)
at AppMain.databaseSchemaOlustur(AppMain.java:117)
at AppMain.main(AppMain.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
2005-10-11 13:18:58,921 DEBUG DefaultConnectionTester:67 - Testing a Connection in response to an Exception:
java.sql.SQLException: Column 'b.bb' is not the same data type as referencing column 'a.b' in foreign key 'FK17E3CD0A98C01'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:364)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2754)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2195)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:620)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:483)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:445)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeImpl(JtdsStatement.java:623)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:1042)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeUpdate(JtdsStatement.java:999)
at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:64)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:163)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:99)
at AppMain.databaseSchemaOlustur(AppMain.java:117)
at AppMain.main(AppMain.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)
2005-10-11 13:18:58,921 ERROR SchemaExport:167 - Unsuccessful: alter table aadd constraint FK17E3CD0A98C01 foreign key (b) references b
2005-10-11 13:18:58,937 ERROR SchemaExport:168 - Column 'b.bb' is not the same data type as referencing column 'a.b' in foreign key 'FK17E3CD0A98C01'.

Half solution:
if I change char(12) to varchar(12) then it is ok.
<hibernate-mapping>
<class name="B" table="b" >
<id name="bb" unsaved-value="null">
<column name="bb" length="12" sql-type="varchar(12)" not-null="true"/>
<generator class="assigned"/>
</id>
...

why I can't use char(12)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 8:38 am 
Newbie

Joined: Tue Oct 18, 2005 8:05 am
Posts: 1
Use following column mapping:
Code:
<column name="bb" length="12" sql-type="[b]char[/b]" not-null="true"/>

You should not specify "(12)" in sql-type attribute because there is no such SQL type "char(12)". You set the length of column in the length attribute.[/b]


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.