-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate doesn't recognise java.util.Set
PostPosted: Wed Jan 17, 2007 5:25 am 
Newbie

Joined: Tue Jan 16, 2007 1:26 pm
Posts: 5
Location: Vienna
Somehow I cannot use Set instead of TreeSet. The code works well if I replace in all methods Set with TreeSet. In the documentation however it's recommended to use interfaces like Set, List or Collection and not implementations. Someone any idea what wrong?




Hibernate version: 3.2.1GA

Mapping documents: Only Annotated

Full stack trace of any exception that occurs:
<code>
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(twos)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:138)
at org.hibernate.mapping.Column.getSqlType(Column.java:182)
at org.hibernate.mapping.Table.sqlCreateString(Table.java:394)
at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:848)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:94)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61)
at Main.main(Main.java:84)
</code>


Name and version of the database you are using:MySQL 5
The generated SQL (show_sql=true): None


<code>
import java.util.*;
import javax.persistence.*;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class Main {

@Entity
@Table(name="manyparttwo")
public static class ManyPartTwo {

@Id
@GeneratedValue
private Integer id;

private Set<ManyPartOne> ones = new TreeSet<ManyPartOne>();

@ManyToMany(
targetEntity=ManyPartOne.class,
cascade=CascadeType.PERSIST,
mappedBy="twos"
)
public Set<ManyPartOne> getOnes() {
return ones;
}

public void setOnes(Set<ManyPartOne> ones) {
this.ones = ones;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

}

@Entity
@Table(name="manypartone")
public static class ManyPartOne {

@Id
@GeneratedValue
private Integer id;

private Set<ManyPartTwo> twos = new TreeSet<ManyPartTwo>();

@ManyToMany(

targetEntity=ManyPartTwo.class,
cascade=CascadeType.PERSIST
)
@JoinTable(
name="many2many",
joinColumns={@JoinColumn(name="one", referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="two", referencedColumnName="id")}
)
public Set<ManyPartTwo> getTwos() {
return twos;
}

public void setTwos(Set<ManyPartTwo> twos) {
this.twos = twos;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}
}

public static void main(String[] args) {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(Main.ManyPartOne.class);
cfg.addAnnotatedClass(Main.ManyPartTwo.class);
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");

new SchemaExport(cfg).create(true, false);

}

}
</code>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 5:48 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi Mike,

You cannot mix where the annotations are. You must annotate either everything at the getter level or everything at variable declartion level.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject: Thanks,
PostPosted: Wed Jan 17, 2007 5:57 am 
Newbie

Joined: Tue Jan 16, 2007 1:26 pm
Posts: 5
Location: Vienna
andydale wrote:
Hi Mike,

You cannot mix where the annotations are. You must annotate either everything at the getter level or everything at variable declartion level.

Cheers,

Andy


Thank you very much, that solved this problem and my problem with the association table. Somehow I was thinking that ManyToMany has to be defined at getter method level. Anyway that's great :-)

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 22, 2007 6:19 pm 
Newbie

Joined: Thu Oct 20, 2005 11:09 am
Posts: 5
Location: Natick, MA
Mike, can you post the final version of your code? I'm not quite understanding the solution. I'm having the same problem.

_________________
----
<a href="http://planet-geek.com/">Planet Geek!</a>


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