-->
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.  [ 6 posts ] 
Author Message
 Post subject: inverseJoinColumn is ignored in @JoinTable
PostPosted: Fri Oct 14, 2005 6:09 pm 
Newbie

Joined: Fri Oct 14, 2005 5:47 pm
Posts: 6
Hibernate version: 3.1rc1

Mapping documents: Annotations

Name and version of the database you are using: MySQL Ver 14.7

The generated SQL (show_sql=true): create table InGenre (isbn varchar(255) not null, elt varchar(255))

Here is the code:
Code:
@OneToMany
@JoinTable(
        table=@Table( name="InGenre" ),
        joinColumns = { @JoinColumn( name = "isbn", nullable = false ) },
        inverseJoinColumns = @JoinColumn( name = "genre" , nullable = false )
)
@Type( type = "mybookshelf.model.usertypes.GenreUserType" )
public Set<Genre> getGenres() {
    return genres;
}


Genre is an enum, with the type set to the "UserType for persisting an Enum with a VARCHAR column" found at http://www.hibernate.org/265.html.

The problem is that nothing I put in that JoinColumn annotation seems to have any affect on the schema that is generated by SchemaExport. But I need it to be not null, and I'd like to change the name.

You can change @OneToMany to @ManyToMany and the same schema results.


Top
 Profile  
 
 Post subject: Further problems...
PostPosted: Sun Oct 16, 2005 2:32 pm 
Newbie

Joined: Fri Oct 14, 2005 5:47 pm
Posts: 6
I noticed in other enum related posts ( specifically http://forum.hibernate.org/viewtopic.php?t=946264 ) that with annotations you can have hibernate map the enum based on the underlying DB column type.

Although it is not a desirable solution, I edited the DDL for the InGenre table to:
Code:
create table InGenre (isbn varchar(255) not null, genre varchar(255) not null )

thinking that maybe the problem was only with the schema export and that hibernate would pick up on the mapping. Unfortunately, this is what I got:
Code:
(util.JDBCExceptionReporter          72  ) null,  message from server: "Unknown column 'elt' in 'field list'"


So, why does the inverse column mapping get ignored completely? I can't even specify the name, much less the type or other constraints, and we can't go around with elt as the name of all our 'weird' columns.

Furthermore, I don't want to have to maintain the DDL by hand, this is a small reference application we are working on right now, but when we start to have multiple columns like this, going back and fixing the generated DDL every time we change it is going to become a nightmare.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 5:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Have a look at the annotations doc on collection of user types, inverseJoincolumns is not used in this case.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 7:48 pm 
Newbie

Joined: Fri Oct 14, 2005 5:47 pm
Posts: 6
emmanuel wrote:
Have a look at the annotations doc on collection of user types, inverseJoincolumns is not used in this case.

Then what do I use? User types are barely even mentioned in the annotations doc.

Is there no way of setting the name/type/constraints on the many side?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 9:35 am 
Newbie

Joined: Fri Oct 14, 2005 5:47 pm
Posts: 6
Furthermore, if I don't use the user type and instead rely on the enum type guessing behavior, it still ignores the inverseJoinColumn.

I get:
Code:
(type.EnumType                       203 ) Unable to guess enum type, default to INTEGER
com.mysql.jdbc.NotImplemented: Feature not implemented
   at com.mysql.jdbc.PreparedStatement.getParameterMetaData(PreparedStatement.java:951)
   at org.hibernate.type.EnumType.guessTypeByParameter(EnumType.java:200)
   at org.hibernate.type.EnumType.guessType(EnumType.java:147)
   at org.hibernate.type.EnumType.nullSafeSet(EnumType.java:113)
   at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:145)
   at
...
(util.JDBCExceptionReporter          71  ) SQL Error: 1054, SQLState: 42S22
(util.JDBCExceptionReporter          72  ) null,  message from server: "Unknown column 'elt' in 'field list'"
(def.AbstractFlushingEventListener   299 ) Could not synchronize database state with session

It looks to me like the problem is that it is still not reading the annotation, otherwise it would get the column name right, and would be able to figure out the type.

Surely there is something I'm missing here. Or are enums on the many side just not supported?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 3:12 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#d0e1596

_________________
Emmanuel


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