JPA concatenating table names for parent/child @OneToMany

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-03-17T20:43:54Z Indexed on 2010/03/17 20:51 UTC
Read the original article Hit count: 260

Filed under:
|

We are trying to use a basic @OneToMany relationship:

@Entity
@Table(name = "PARENT_MESSAGE")
public class ParentMessage {

 @Id
 @Column(name = "PARENT_ID")
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Integer parentId;

 @OneToMany(fetch=FetchType.LAZY)
 private List childMessages;

 public List getChildMessages() {
  return this.childMessages;
 }
    ...
}

@Entity
@Table(name = "CHILD_MSG_USER_MAP")
public class ChildMessage {

 @Id
 @Column(name = "CHILD_ID")
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Integer childId;

 @ManyToOne(optional=false,targetEntity=ParentMessage.class,cascade={CascadeType.REFRESH}, fetch=FetchType.LAZY)
 private ParentMessage parentMsg;

        public ParentMessage getParentMsg() {
  return parentMsg;
 }
    ...
}
   ChildMessage child = new ChildMessage();
   em.getTransaction().begin();
   ParentMessage parentMessage = (ParentMessage) em.find(ParentMessage.class, parentId);
   child.setParentMsg(parentMessage);
   List list = parentMessage.getChildMessages();
   if(list == null) list = new ArrayList();
   list.add(child);
   em.getTransaction().commit();

We receive the following error. Why is OpenJPA concatenating the table names to APP.PARENT_MESSAGE_CHILD_MSG_USER_MAP? Of course that table doesn't exist.. the tables defined are APP.PARENT_MESSAGE and APP.CHILD_MSG_USER_MAP

Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Table/View 'APP.PARENT_MESSAGE_CHILD_MSG_USER_MAP' does not exist. {SELECT t1.CHILD_ID, t1.PARENT_ID, t1.CREATED_TIME, t1.USER_ID FROM APP.PARENT_MESSAGE_CHILD_MSG_USER_MAP t0 INNER JOIN APP.CHILD_MSG_USER_MAP t1 ON t0.CHILDMESSAGES_CHILD_ID = t1.CHILD_ID WHERE t0.PARENTMESSAGE_PARENT_ID = ?} [code=30000, state=42X05]

© Stack Overflow or respective owner

Related posts about jpa

Related posts about openjpa