my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes Could not determine type for: java.util.Set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not determine type for: java.util.Set" Watch "Could not determine type for: java.util.Set" New topic
Author

Could not determine type for: java.util.Set

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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

Joined: Nov 13, 2008
Posts: 84

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

Joined: Jun 28, 2008
Posts: 580
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

Joined: Jun 28, 2008
Posts: 580
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

Joined: Nov 13, 2008
Posts: 84

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

Joined: Jun 28, 2008
Posts: 580
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

Joined: Jun 28, 2008
Posts: 580

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

Joined: Dec 21, 2009
Posts: 1
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

Joined: Jul 31, 2004
Posts: 1
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

Joined: Oct 26, 2011
Posts: 1
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
Greenhorn

Joined: Jan 21, 2011
Posts: 29

hi,

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

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

and enjoy.

cheers,
Prateek Singh
 
 
subject: Could not determine type for: java.util.Set
 
Similar Threads
mapping problem and joinColumns
Mysql auto generated PK used for another table and JPA
How to join two tables having each two fileds in common? (seems like @OneToMany with 2 joinColumns)
Cascade Type problem
OneToOne composite key