-->
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.  [ 3 posts ] 
Author Message
 Post subject: H8 seems to don't translate properties to DB fields
PostPosted: Wed Aug 26, 2009 3:47 am 
Newbie

Joined: Wed Aug 26, 2009 3:00 am
Posts: 3
Location: Naples, IT
Hi to all!
I'm new to H8 and I've a strange trouble.

I have a simple Many-To-One Relationship:
Street 1 - N Street number

In Streets.java I have:
Code:
@Entity
@Table(name = "STREETS")
public class Streets implements java.io.Serializable {
    // ... various fields ...
    private List<StreetNumbers> streetNumbers = new ArrayList<StreetNumbers>(0);
    // ..

    @OneToMany(mappedBy="street") // It points to a "street" property in StreetNumbers.java
    public List<StreetNumbers> getStreetNumbers() {
      return this.streetNumbers;
    }
   
    public void setStreetNumbers(List<StreetNumbers> streetNumbers) {
   this.streetNumbers = streetNumbers;
    }
}


In StreetNumbers.java I have:
Code:
@Entity
@Table(name = "STREET_NUMBERS")
public class StreetNumbers implements java.io.Serializable {
    // ... various fields ...
    private Streets street;
    // ...
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ID_STREET",  nullable = false, insertable = false, updatable = false)
    public Streets getStreet() {
   return this.street;
    }
   
    public void setStreets(Streetsstreet) {
   this.street= street;
    }
}


But this implementation raises the following exception:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(StreetNumbers)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
at it.eng.elisa.coop.variazioni.acsor.persistence.SessionFactoryManager.<clinit>(SessionFactoryManager.java:34)
... 3 more

But if I put the @OneToMany and @ManyToOne annotations on the properties instead of the fields, it works fine:
Street
Code:
   @OneToMany(mappedBy="street")
   private List<StreetNumbers> streetNumbers= new ArrayList<StreetNumbers>(0);

StreetNumbers.java
Code:
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ID_STREET",  nullable = false, insertable = false, updatable = false)
   private Streets street;


I don't understand this behaviour.

PS:
I have the same problem with the @Column annotations.
If I put them on the getter, H8 uses the name of property to access to the DB causing an error.
If I put them on the class field, H8 uses the name set in @Column(name = ...).

Thanks in advance!

_________________
Stay hungry, stay foolish.


Top
 Profile  
 
 Post subject: Re: H8 seems to don't translate properties to DB fields
PostPosted: Wed Aug 26, 2009 2:10 pm 
Newbie

Joined: Wed Aug 26, 2009 3:00 am
Posts: 3
Location: Naples, IT
I found the problem.

I put the @Id on the property and the @Column annotations on the getters and this causes some problems.

_________________
Stay hungry, stay foolish.


Top
 Profile  
 
 Post subject: Re: H8 seems to don't translate properties to DB fields
PostPosted: Thu Aug 27, 2009 9:11 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Indeed!

Both are valid strategies, but you need to be consistent. Either all annotations on properties, or all annotations on methods. Don't mix and match.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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