Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not determine type for: java.util.Set

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem by mapping these two tables:

Table:
CONTAINER
--------------
PK,FK ID_APPLICATION
PK ID_CONTAINER
NAME

Table:
CONTENT
--------------
PK,FK ID_APPLICATION
PK,FK ID_CONTAINER
PK ID_CONTENT
NAME

Now, I want to map these two tables via Hibernate-JPA:






I get the failure:

State: FAILED
Reason: javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(container)]

What is wrong with this mapping? Any Ideas?


The Information under http://dewarim.de/wms/error/hibernate_could_not_determine_type does not help me out.
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that your problem it's with the referenceColumn attribute, check this http://www.coderanch.com/t/422618/Object-Relational-Mapping/Bidirection-join-broken-one-direction .
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I reference to a composite key, so this could be the problem:



But when I delete the reference from my Entity "Container",
then the hibernate-mapping does not complain any mapping-failure,
that means all my referenceColumns (and my composite keys) are right.



However, I need this relationship.

Any Ideas what is wrong?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
upps..is that really correct?
:
adapted from http://www.coderanch.com/t/422618/Object-Relational-Mapping/Bidirection-join-broken-one-direction:
..referenceColumnName wanted Java attributes not SQL columns..


@JoinColumn(name = "ID_CONTAINER", referencedColumnName = "ID_CONTAINER", nullable = false)

Both the "name" and the "referencedColumnName" should be the names of the corresponding SQL-Columns,
that means in my SQL-Table CONTAINER the column "ID_CONTAINER" is declared as a PrimaryKey and in
in my SQL-Table CONTENT column "ID_CONTAINER" is declared as a ForeignKey (and PrimaryKey).

So I do not reference via JAVA-Attributes as this would be wrong! Am I right?

 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
precisely, that's what i'm talkin' about, the referenceColumName must be the name of the property of the Entities not the SQL column names.

you must have




regards,
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This:


is very strange for me, as I have learned, that the referencedColumnName should be the name of the SQL-Column-Name (such as the name-Attribute)).

The other thing is, I have mapped other tables successfully with referencedColumnName and SQL-Column-Names.

But this is the first scenario in which I have to map a foreign-key, which is a composite key:




This also does not work, the same failure occurs:

State: FAILED
Reason: javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(container)]



I cannot find the reason.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

referencedColumnName should be definitlythe name of the corresponing (sql-)column
and not the name of the corresponding property! In the Hibernate-Manual, the SQL-Column is used!

But this does not help me out. I cannot find a solution for my problem.
 
Stefan Goor
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same issue but found it was caused by where the @ManyToOne and @JoinColumn annotations were placed.

Generally I work with generated code for hibernate objects so the annotations are placed above the getter methods in the generated Java code, however when I tried to add some annotations to someone else's manually written hibernate code I got the error:




After being baffled for a while I noticed that the class I was modifying had all the other existing annotations on the private member variables. When I moved my annotations away from the getter method and onto the private member variable the errors disappeared and seemed to work as expected.

Hope this helps...
 
Hernan Lopez
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stiofan Uí Goida wrote:I had the same issue but found it was caused by where the @ManyToOne and @JoinColumn annotations were placed.

Generally I work with generated code for hibernate objects so the annotations are placed above the getter methods in the generated Java code, however when I tried to add some annotations to someone else's manually written hibernate code I got the error:




After being baffled for a while I noticed that the class I was modifying had all the other existing annotations on the private member variables. When I moved my annotations away from the getter method and onto the private member variable the errors disappeared and seemed to work as expected.

Hope this helps...



Thanks Goida It works for me.
 
Filip Saska
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same problem. In my case the solution was adding an anntation @CollectionOfElements to he getter method (that's where i keep my annotations). Once i discovered this, it was a piece of cake
Hope it helps
 
Prateek Kumar Singh
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

just add annotation @CollectionOfElements on your collection variable. like-

@CollectionOfElements
private Set<model> mySet = new HashSet<model>() ;

and enjoy.

cheers,
Prateek Singh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic