[jboss-user] [EJB 3.0] - Need some help with mapping
MikeDougherty
do-not-reply at jboss.com
Wed Mar 28 14:42:54 EDT 2007
OK, I would appreciate a little help with a mapping issue I am running into. I have what I will call a Type table. This table looks something like this:
| +------------+--------------+
| | Field | Type |
| +------------+--------------+
| | TABLE_NAME | varchar(25) |
| | ITEM_ID | varchar(10) |
| | ITEM_FIELD | varchar(25) |
| | ITEM_VALUE | varchar(255) |
| +------------+--------------+
|
The TABLE_NAME, ITEM_ID, and ITEM_FIELD columns make up the primary key.
I have this table mapped to a Type object, with a TypePK @IdClass. This works fine.
However, what I need to do is map certain rows in this table to a field in another object. For example, if my STORE table looks like:
| +------------+--------------+
| | Field | Type |
| +------------+--------------+
| | STORE_NAME | varchar(255) |
| | STORE_ID | varchar(10) |
| | STORE_TYPE_ID | varchar(25) |
| +------------+--------------+
|
The STORE_TYPE_ID value needs to be mapped to the ITEM_ID field in the TYPE table where TABLE_NAME = "STORE" and an ITEM_FIELD = "STORE_TYPE".
I've tried subclassing Type (with @Inheritance, and @DiscriminatorValue annotations) but that does not seem to be giving me the desired result.
| @Entity
| @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
| @DiscriminatorColumn(name="LIST_FIELD", discriminatorType = DiscriminatorType.STRING)
| @DiscriminatorValue("STORE_TYPE")
| public class StoreType extends Type {
| }
|
| entityManager.createQuery("select storeType from StoreType storeType");
|
Generates the following error:
| Caused by: java.sql.SQLException: ORA-00942: table or view does not exist
|
Any ideas how I might be able to annotate these objects in order to get the result I am looking for?
| @Entity
| @Table(name = "STORE")
| public class Store implements Serializable {
| @Id
| @Column(name = "STORE_ID")
| public Long getId() {
| return id;
| }
|
| public void setId(Long id) {
| this.id = id;
| }
|
| @OneToOne(mappedBy="id")
| public StoreType getType() {
| return type;
| }
|
| public void setType(StoreType type) {
| this.type = type;
| }
|
| @Column(name = "STORE_NAME")
| public String getName() {
| return name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
| }
|
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4032498#4032498
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4032498
More information about the jboss-user
mailing list