Hibernate version: 3.2 cr1
Hibernate Annotations version: 3.1 beta10
I'm trying to use annotations to map an existing schema where a table (InventoryItem) table as a composite primary key comprised of 2 foreign key references. No matter what I try I keep getting this exception...
org.hibernate.MappingException: property not found: location on entity InventoryItem
The schema is defined as such...
Code:
create table TblLocation
(
id number(38,0) not null,
name varchar2(255) not null,
primary key (id)
);
create table TblItem
(
id number(38,0) not null,
name varchar2(255) not null,
primary key (id)
);
create table TblInventoryItem
(
location_id number(38,0) not null,
item_id number(38,0) not null,
quantity number(38,0) not null,
price number(38,2) not null,
primary key (location_id,item_id),
foreign key (location_id) references TblLocation(id),
foreign key (item_id) references TblItem(id)
);
And here are the mapped classes
Code:
@Entity
@Table(name="TblLocation")
@SequenceGenerator(name="LocationSeq",sequenceName="LOCATION_SEQ")
public class Location
{
private long id;
private String name;
private Set<InventoryItem> _items;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="LocationSeq")
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
@OneToMany(mappedBy="location")
public Set<InventoryItem> getItems()
{
return _items;
}
public void setItems(Set<InventoryItem> items)
{
_items = items;
}
}
@Entity
@Table(name="TblItem")
@SequenceGenerator(name="ItemSeq",sequenceName="ITEM_SEQ")
public class Item
{
private long id;
private String name;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="ItemSeq")
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
@Entity
@Table(name="TblInventoryItem")
@IdClass(InventoryItemId.class)
public class InventoryItem
{
private Location _location;
private Item _item;
private long _quantity;
private float _price;
@Id
@ManyToOne
@JoinColumn(name="location_id")
public Location getLocation()
{
return _location;
}
public void setLocation(Location location)
{
_location = location;
}
@Id
@ManyToOne
@JoinColumn(name="item_id")
public Item getItem()
{
return _item;
}
public void setItem(Item item)
{
_item = item;
}
public float getPrice()
{
return _price;
}
public void setPrice(float price)
{
_price = price;
}
public long getQuantity()
{
return _quantity;
}
public void setQuantity(long quantity)
{
_quantity = quantity;
}
}
@Embeddable
public class InventoryItemId
{
private Location _location;
private Item _item;
public Item getItem()
{
return _item;
}
public void setItem(Item item)
{
_item = item;
}
public Location getLocation()
{
return _location;
}
public void setLocation(Location location)
{
_location = location;
}
}
Is it possible to map a composite primary key using foreign key references? I've tried several variations using @ManyToOne, @JoinColumn, ... but haven't been able to get this to work.
any help would be appreciated.
thanks,
Brett