Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA / Oracle NoSql / Eclipselink - Record Insertion Issue (JPA using EclipseLink with One-to-Many Relationship in Oracle NoSql DB throws javax.persistence.PersistenceException: Exception [EclipseLink-90000] (Eclipse Persistence Services - 2.6.4.v20160829-4406)
JPA / Oracle NoSql / Eclipselink - Record Insertion Issue [message #1749793] Mon, 12 December 2016 11:05
Anurag Ambasta is currently offline Anurag AmbastaFriend
Messages: 2
Registered: December 2016
Junior Member
I am working on JPA with Oracle NoSql DB - using eclipselink org.eclipse.persistence.core-2.6.4.jar
When inserting data in One-To_many relationship, I am getting:
javax.persistence.PersistenceException: Exception [EclipseLink-90000] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.eis.EISException
....
....
Internal Exception: javax.resource.ResourceException: java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord



I have two classes Person and Address, which have one-to-many relationship. The code snippet below:

@Entity
@NoSql (dataFormat = DataFormatType.MAPPED)
public class Person implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    @Field(name = "_id")
    private String id;

    private String firstName;

    private String lastName;

    @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<Address> addresses = new ArrayList<>();


AND
@Entity
@NoSql (dataFormat = DataFormatType.MAPPED)
public class Address implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    @Field(name = "_id")
    private String id;

    private String street;

    private String city;

    private String country;

    private Integer pincode;

    @JoinField(name = "PERSON_ID", referencedFieldName = "_id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Person person;


My Main function is as below:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestPU");
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx = em.getTransaction();

    try {
        tx.begin();

        Person p1 = new Person();
        p1.setFirstName("fn");
        p1.setLastName("ln");

        List<Address> addrList = new ArrayList<>();

        Address addr1 = new Address();
        addr1.setStreet("str");
        addr1.setCity("City");
        addr1.setCountry("Ctry");
        addr1.setPincode(123456);
        addrList.add(addr1);

        Address addr2 = new Address();
        addr2.setStreet("str2");
        addr2.setCity("City2");
        addr2.setCountry("Ctry2");
        addr2.setPincode(223456);
        addrList.add(addr2);

        p1.setAddresses(addrList);     
        em.persist(p1);
        tx.commit();


My persistence.xml is as below:

  <persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.target-database" value="org.eclipse.persistence.nosql.adapters.nosql.OracleNoSQLPlatform"/>
      <property name="eclipselink.nosql.connection-spec" value="org.eclipse.persistence.nosql.adapters.nosql.OracleNoSQLConnectionSpec"/>
      <property name="eclipselink.nosql.property.nosql.host" value="dockerHost:5002"/>
      <property name="eclipselink.nosql.property.nosql.store" value="camiantDBstore"/>
      <property name="eclipselink.logging.level" value="FINEST"/>
    </properties>
  </persistence-unit>
</persistence>


When I am executing my main method following exception is thrown:

javax.persistence.PersistenceException: Exception [EclipseLink-90000] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.eis.EISException
Error Code: 000
Call: Executing MappedInteraction()
    spec => null
    properties => {nosql.operation=PUT_IF_ABSENT}
Internal Exception: javax.resource.ResourceException: java.lang.ClassCastException: java.lang.String cannot be cast to org.eclipse.persistence.internal.nosql.adapters.nosql.OracleNoSQLRecord
    input => [DatabaseRecord(
    PERSON.FIRSTNAME => fn
    PERSON.LASTNAME => ln
    PERSON.ID => F9A2D757-BA55-4218-BC8F-0D6304649AEC
Error Code: 000
Call: Executing MappedInteraction()
    PERSON.ADDRESSES_ID => [8E6F3B7F-C16E-4378-9BC7-7BBB2EBE5654, 638D01DA-6B06-4AB2-9E8B-F4A6DACA1D6C, B92A85D0-9161-4C35-8A44-C06C7C53E25F])]
    spec => null
Query: InsertObjectQuery(test.Person@5dda768f)
    properties => {nosql.operation=PUT_IF_ABSENT}
    input => [DatabaseRecord(
    PERSON.FIRSTNAME => fn
    PERSON.LASTNAME => ln
    PERSON.ID => F9A2D757-BA55-4218-BC8F-0D6304649AEC
    PERSON.ADDRESSES_ID => [8E6F3B7F-C16E-4378-9BC7-7BBB2EBE5654, 638D01DA-6B06-4AB2-9E8B-F4A6DACA1D6C, B92A85D0-9161-4C35-8A44-C06C7C53E25F])]
Query: InsertObjectQuery(test.Person@5dda768f)
    at org.eclipse.persistence.eis.EISException.resourceException(EISException.java:65)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:879)
    at testnosqljpa.TestNoSqlJPA.main(TestNoSqlJPA.java:60)
Caused by: Exception [EclipseLink-90000] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.eis.EISException
    at org.eclipse.persistence.eis.EISException.resourceException(EISException.java:74)


Any help appreciated.
Previous Topic:Eclipselink 2.6.4 LEFT JOIN TREAT QUERY Not working properly
Next Topic:JPA ManyToMany relationship in Oracle NoSql - @JoinTable
Goto Forum:
  


Current Time: Mon Dec 11 22:59:56 GMT 2017

Powered by FUDForum. Page generated in 0.01700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software