Hibernate annotation many-to-one mapping generating odd schema?

I suspect the problem is that you're using a concrete HashSet instead of the Set interface. Try this (assuming it has an Id somewhere).

I suspect the problem is that you're using a concrete HashSet instead of the Set interface. Try this (assuming it has an Id somewhere): @Entity public class Schedule implements java.io. Serializable { private String scheduleName; private Set steps = new HashSet(); @OneToMany(mappedBy="schedule", cascade=CascadeType.

ALL, fetch=FetchType. EAGER) public Set getSteps() { return steps; } // other properties, getters, setters } Also note how I initialized the steps property. Let me quote the documentation about this: 6.1.Persistent collections ... Notice how the instance variable was initialized with an instance of HashSet.

This is the best way to initialize collection valued properties of newly instantiated (non-persistent) instances. When you make the instance persistent, by calling persist() for example, bernate will actually replace the HashSet with an instance of bernate's own implementation of Set. And make sure that: both entities have an @Id property (the part you're showing is not enough to confirm that).

Step is implementing equals/hashCode correctly (see the references below). References bernate Core Reference Guide 4.3.Implementing equals() and hashCode() 6.1. Persistent collections Update: Can't reproduce (I don't have PostgreSQL installed by I don't think it is that relevant). I used the following entities: @Entity public class Step implements java.io.

Serializable { private Long id; private String duration; private String stepType; private Schedule schedule; @ManyToOne(fetch = FetchType. LAZY) public Schedule getSchedule() { return schedule; } @Id @GeneratedValue public Long getId() { return id; } // getters, setters, equals, hashCode } And: @Entity public class Schedule implements java.io. Serializable { private Long id; private String scheduleName; private Set steps = new HashSet(); @OneToMany(mappedBy = "schedule", cascade = CascadeType.

ALL, fetch = FetchType. EAGER) public Set getSteps() { return steps; } @Id @GeneratedValue public Long getId() { return id; } // getters, setters } Here is the generated DDL: create table Schedule ( id bigint generated by default as identity (start with 1), scheduleName varchar(255), primary key (id) ) create table Step ( id bigint generated by default as identity (start with 1), duration varchar(255), stepType varchar(255), schedule_id bigint, primary key (id) ) alter table Step add constraint FK277AEC7B775928 foreign key (schedule_id) references Schedule I don't even understand how you could use a HashSet in your OneToMany, bernate complained (as expected to be honest) when I tried: Caused by: org.hibernate. AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.stackoverflow.

Q4083744.Schedule.steps.

Good points. I didn't have equals/hashCode, so that is now fixed. Though by changing the field type from HashSet to Set I get an exception "org.hibernate.

MappingException: Could not determine type for: java.util. Set". – speshak Nov 3 '10 at 3:51 @speshak: Using an HashSet isn't right but something else might still be wrong.

Actually, what is this MashStep I didn't notice earlier? Can you show accurate mappings? – Pascal Thivent Nov 3 '10 at 6:08 MashStep was copied from the wrong class when I was snipping the non-interesting things from the class.

I've updated the question to be correct. I also tried adding targetEntity=Step. Class to my @OneToMany to fix the exception I was getting, no luck there.

– speshak Nov 3 '10 at 16:04 @speshak Are you using the right javax.persistence. Entity annotation? Does the step have an Id?

How can I reproduce? – Pascal Thivent Nov 3 '10 at 16:25 I have the entity annotated exactly as above. I added the annotations I'm using for Id to Step.

I'm not sure about steps to reproduce, the code is what is shown above (minus getters/setters, which are just the ones generated by netbeans anyway) – speshak Nov 3 '10 at 19:34.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions