-->
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.  [ 1 post ] 
Author Message
 Post subject: Map & property mapping has wrong number of columns
PostPosted: Fri Jan 25, 2008 8:56 pm 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
Hi,

i have problem with my interface in hibernate.

i think there is a problem with interface, it is possible to use interface in my Map object ?

error message:

nested exception is org.hibernate.MappingException: property mapping has wrong number of columns: com.xxxx.model.HousePropertyValue.value type: object

i have House.java file with mapping of Map collection:

Code:

@OneToMany(mappedBy = "house",            fetch = FetchType.LAZY, cascade = CascadeType.ALL,
               targetEntity = com.xxx.model.HousePropertyValue.class)
   @MapKey(name = "valueKey")
   private Map<String, HousePropertyValue> housePropertyValues;



and HousePropertyValue.java (HousePropertyValue interface):

Code:

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="value_type",
   discriminatorType=DiscriminatorType.STRING
)
@Table(name="house_property_value")
@javax.persistence.SequenceGenerator(
   name="seq_house_property_value",
   sequenceName="s_house_property_value",
   allocationSize=1
)
public interface HousePropertyValue extends Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_house_property_value")
   public Long getId();
   public void setId(Long id);
   @Column(name="value_key", nullable = false)
   public String getValueKey();
   public void setValueKey(String valueKey);
   @ManyToOne (fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   @JoinColumn(name = "fk_house_id", referencedColumnName = "id", nullable = false)
   public House getHouse();
   public void setHouse(House house);
   public Object getValue();
   public void setValue(Object value);
}



and HousePropertyDateValue.java - implementation of HousePropertyValue interface:

Code:

@Entity
@DiscriminatorValue("DATE")
@javax.persistence.SequenceGenerator(
   name="seq_house_property_value",
   sequenceName="s_house_property_value",
   allocationSize=1
)
public class HousePropertyDateValue implements HousePropertyValue {

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq_house_property_value")
   private Long id;

   private House house;

   private String valueKey;

   @Column(name="value_date", nullable=false)
   private Date value = new Date();

   public HousePropertyDateValue() {}
   public HousePropertyDateValue(Date value) {      this.value = value;    }
   public Long getId() {       return id;    }
   public void setId(Long id) {         this.id = id;    }
   public String getValueKey() {         return valueKey;    }
   public void setValueKey(String valueKey) {        this.valueKey = valueKey;    }
   public House getHouse() {        return house;    }
   public void setHouse(House house) {        this.house = house;    }
   public Date getValue()    {        return value;    }
   public void setValue( Date value )    {        this.value = value;    }
   public void setValue( Object value )    {        this.value = (Date) value;    }
}



hibernate.cfg.xml:

Code:

<hibernate-configuration>
    <session-factory>
        <mapping class="com.xxx.model.House"/>
        <mapping class="com.xxx.model.HousePropertyValue"/>
        <mapping class="com.xxx.model.HousePropertyDateValue"/>
    </session-factory>
</hibernate-configuration>



thanks!

Ivan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.