E
E
Evgeny Shklyaev2017-01-26 14:53:28
Java
Evgeny Shklyaev, 2017-01-26 14:53:28

Links in jpa don't work. How to describe entity relationships?

Er table diagram:
35cdbdb3ca1d47169b2d250697af94f5.png
Data Model:
Table - J_MESSAGE_PARAM

@Entity
@Table(name = "J_MESSAGE_PARAM", schema = "PKU")
@EqualsAndHashCode
@ToString
public class PkuJMessageParam implements Serializable, Cloneable, IGetId {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    @Getter @Setter private long id;

    @Column(name = "NAME")
    @Getter @Setter private String name;

    @Column(name = "VALUE")
    @Getter @Setter private String value;

    @ManyToOne
    @JoinColumn(name = "ID")
    @Getter @Setter private PkuJMessage jMessage;
}

Table - J_MESSAGE
@Entity
@Table(name = "J_MESSAGE", schema = "PKU")
@EqualsAndHashCode
@ToString
public class PkuJMessage implements Serializable, Cloneable, IGetId {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    @Getter @Setter private long id;

    @Column(name = "DATA")
    @Getter @Setter private byte[] data;

    @Column(name = "FILENAME")
    @Getter @Setter private String filename;

    @Column(name = "USER")
    @Getter @Setter private String user;

    @Column(name = "IS_OUT")
    @Getter @Setter private String isOut;

    @Column(name = "IS_WORKED_OUT")
    @Getter @Setter private String isWorkedOut;

    @Column(name = "IS_SENT")
    @Getter @Setter private String isSent;

    @Column(name = "IS_RESULT")
    @Getter @Setter private String isResult;

    @Column(name = "DESCRIPTION")
    @Getter @Setter private String description;

    @Column(name = "EXECUTION_DATE")
    @Getter @Setter private Timestamp executionDate;

    @Column(name = "NEED_RESTART")
    @Getter @Setter private String needRestart;

    @OneToMany(mappedBy = "jMessage")
    @Getter @Setter private List<PkuJMessageParam> jMessageParams;
}

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"	version="1.0">
  <persistence-unit name="PKU">
    <jta-data-source>jdbc/PKU</jta-data-source>
    <properties>
      <property name="openjpa.Log" value="log4j"/>
      <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
      <property name="javax.persistence.query.timeout" value="60000"/>
      <property name="openjpa.jdbc.DBDictionary" value="db2(batchLimit=50)"/>
      <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
      <property name="openjpa.ConnectionRetainMode" value="on-demand"/>
      <property name="openjpa.FlushBeforeQueries" value="true"/>
      <property name="openjpa.IgnoreChanges" value="false"/>
      <property name="openjpa.TransactionMode" value="local"/>
    </properties>
  </persistence-unit>
</persistence>

When reading the PkuJMessageParam object by id from the base, the jMessage property comes up empty. Although there are corresponding values ​​in the database.
Obtaining an object is performed by the following method:
@PersistenceContext(unitName = "PKU")
    private EntityManager manager;

public T read(long id) {

        LOG.debug(Conv.toFillTextMsg("Читаю объект {0} (id={1})", getClassName().getSimpleName(), id));
        long t = System.currentTimeMillis();

        T item = manager.find(getClassName(), id);
        manager.flush();

        LOG.debug(Conv.toFillTextMsg("Прочитан объект {0} : [{1}]. Время выполнения {2} мс.", getClassName().getSimpleName(), item, System.currentTimeMillis()-t));

        return item;
    }

I'm testing this method with a test servlet. In the debugger, the jMessage property is empty.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Shklyaev, 2017-01-28
@lolchtoo

It wasn't the code, it was the EJB configuration for IBM WebSphere.

A
aol-nnov, 2017-01-26
@aol-nnov

not at all, but, nevertheless .. :)
fasten lombok to the project - the footcloths will go away, but the essence will remain. very comfortably!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question