ManyToOne bidirectional issue

I have two objects: Message and GeneratedMemberMessage. There are more fields than shown here in the code, but they should provide enough context for my question.

I am trying to make a simple OneToMany bidirectional relationship and from everything I read, here's how to do it. You will notice that I use compound keys.

I get the following error and stacktrace. I have seen others who have this problem around firewalls, but I don't have a solution that works for me. Does anyone see a problem here?

As ST says, I use openJPA 1.2.2 in WAS 7.0. I am developing RAD 7.5.4 and EJB 3.0.

Message.java

@Entity
@Table(schema="dbo", name="Messages")
public class Message implements Serializable {

  @Embeddable
  public static class MessagePK implements Serializable {
    @Column(name="SourceApplication")
    String sourceApplication;

    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="MessageId")
    BigDecimal messageId;

    //Getters and setters here

  }


  @EmbeddedId
  MessagePK pk = new MessagePK();
  ...

  @OneToMany(cascade={CascadeType.ALL}, mappedBy="message")
  List<GeneratedMemberMessage> generatedMemberMessages = new ArrayList<GeneratedMemberMessage>();

  ...

}

GeneratedMemberMessage.java

@Entity
@Table(schema="dbo", name="GeneratedMemberMessages")
public class GeneratedMemberMessage implements Serializable {
  @Embeddable
  public static class GMMPK implements Serializable {

    @Column(name="SourceApplication")
    String sourceApplication;

    @Column(name="MessageId")
    int messageId;

    @Column(name="MessageGenerationDateTime")
    Date messageGenerationDateTime;

    //Getters and setters here

  }
  ...

  @ManyToOne(optional = true)
  @JoinColumns({  
    @JoinColumn(name="sourceApplication", referencedColumnName="SourceApplication"),  
    @JoinColumn(name="messageId", referencedColumnName="MessageId")
  }) 
  Message message;

  ...

}

My EJB Method

public Message newMessage(String sourceApplication, String text, int priority, String type){
    Message m = new Message(sourceApplication);
    m.setMessageText(text);
    m.setMessagePriority(priority);
    m.setMessageType(type);
    m.setSysLstUpdtUserId("me");    
    em.persist(m);
    return m;
}

Stacktrace

[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R javax.ejb.EJBException: See nested exception; nested exception is: <openjpa-1.2.2-SNAPSHOT-r422266:778978M-OPENJPA-975 fatal user error> org.apache.openjpa.persistence.ArgumentException: Field "com.bcbst.bamp.jpa.Message.generatedMemberMessages" cannot declare that it is mapped by another field. Its mapping strategy (org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy) does not support mapping by another field.
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R Caused by: <openjpa-1.2.2-SNAPSHOT-r422266:778978M-OPENJPA-975 fatal user error> org.apache.openjpa.persistence.ArgumentException: Field "com.bcbst.bamp.jpa.Message.generatedMemberMessages" cannot declare that it is mapped by another field. Its mapping strategy (org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy) does not support mapping by another field.
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.strats.AbstractFieldStrategy.assertNotMappedBy(AbstractFieldStrategy.java:59)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.strats.HandlerFieldStrategy.map(HandlerFieldStrategy.java:71)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:121)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:80)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:454)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:419)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(ClassMapping.java:879)
[3/17/10 14:55:05:457 EDT] 0000001e SystemErr     R     at org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:339)
...
+3
6

, .

persistence.xml. Message persistence.xml <class>Message</class>.

+11

HandlerFieldStrategy JPA, Entity XYZ, Entity ABC [ ], , ABC persistence.xml [META- INF/persistence.xml]

+2

MessagePK? ?

0

. JPA Websphere 7, .

? mappedBy="XXX".

. , .

Edit

- JPQL. .

0

.

!

, equals() hashCode() pk object.

, -.

0

I had the same problem, but in my case I got mixed up mappedBy = "foo" where foo should declare a field! Not a pillar.

0
source

Source: https://habr.com/ru/post/1737412/


All Articles