Hi,
On Implementing, Bidirectional ManyToOne Association using Hibernate OGM - hibernate-ogm-5.0.0.Alpha1 (also tried with hibernate-ogm-4.2.0.Final) and MongoDB (version 3.0.4) it ended up with an Null Pointer Exp org.hibernate.ogm.datastore.mongodb.MongoDBDialect.insertOrUpdateAssociation(MongoDBDialect.java:624) (PFB, is the Stack Trace)
Test Case.
1) Have Employeer and Employee Class having oneToMany and ManyToOne Association Respectively (PFB, contains POJO class for the same)
2) Inserted Record in Employeer Table (Got Successfully Inserted) in MongoDB
[Mongo DB Details on Insert]
{
"_id" : "288d0843-63d7-4177-9428-3c6795c0470e",
"name" : "Hibernate"
}
3) Tried Inserting an Employee Information with Employeer Details. It was successfully inserted with Employeer ID
[Mongo DB Details on Insert with Employeer Information]
{
"_id" : "eca8e45d-cbde-4d4c-a5cc-21640d177a58",
"EmployerID" : "288d0843-63d7-4177-9428-3c6795c0470e",
"name" : "DNadar"
}
4) Verified Employeer Table No Information of Employee is stored in the table (It should have had an Array having Employee ID)
5) On Verifying Log, i could see Null Pointer Exception at
org.hibernate.ogm.datastore.mongodb.MongoDBDialect.insertOrUpdateAssociation(MongoDBDialect.java:624)Tried Integrating the Source Code to find out the Issue, AssociatonContext's getEntityTuple Method is returning Null value for hostingEntity(Employeer in my case)
On verifying the Object, the ObjectState is Null with AssociationContext in
Managed state. And On insertOrUpdateAssociation method it is trying to get the EntityTuple which is null and threw null pointer exception.
Tried Verifying the same with loading the Employeer Object (with Session.get(Class, id)) and then Set it into Employee Object. in this case it worked fine (Had an Array Object created at Employeer Entity having Employee Id). AssociationContext in that case was in
Loading State.
Please Note : On the Source Code of Verison 5.0.0.Alpha1 i can see some TODO statement(MongoDBDialect class, Methodname - insertOrUpdateAssociation Line no -623 ) //TODO would that fail if getCollectionRole has dots? (Not sure what it means)Let me know in case of any more information
Thank you,
Domnic nadar
Code:
java.lang.NullPointerException
at org.hibernate.ogm.datastore.mongodb.MongoDBDialect.insertOrUpdateAssociation(MongoDBDialect.java:624)
at org.hibernate.ogm.dialect.impl.ForwardingGridDialect.insertOrUpdateAssociation(ForwardingGridDialect.java:132)
at org.hibernate.ogm.dialect.impl.BatchOperationsDelegator.insertOrUpdateAssociation(BatchOperationsDelegator.java:126)
at org.hibernate.ogm.util.impl.AssociationPersister.flushToDatastore(AssociationPersister.java:170)
at org.hibernate.ogm.persister.impl.EntityAssociationUpdater.addNavigationalInformationForInverseSide(EntityAssociationUpdater.java:161)
at org.hibernate.ogm.persister.impl.EntityAssociationUpdater.addNavigationalInformationForInverseSide(EntityAssociationUpdater.java:114)
at org.hibernate.ogm.persister.impl.OgmEntityPersister.addToInverseAssociations(OgmEntityPersister.java:1278)
at org.hibernate.ogm.persister.impl.OgmEntityPersister.insert(OgmEntityPersister.java:1386)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:447)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:333)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:335)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.ogm.dialect.eventstate.impl.EventContextManagingFlushEventListener.onFlush(EventContextManagingFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2890)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2266)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
at org.hibernate.ogm.transaction.impl.ForwardingTransactionCoordinatorOwner.beforeTransactionCompletion(ForwardingTransactionCoordinatorOwner.java:37)
[code]
Sample Test cases : Employeer Class
[code]
@Entity
@Table(name = "Employer")
public class Employeer implements Serializable
{
private static final long serialVersionUID = -8732345803771451030L;
private String id;
private String name;
private Set<Employee> employees;
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name="uuid", strategy="uuid2")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(fetch=FetchType.EAGER,mappedBy="employeer")
@Cascade({ CascadeType.PERSIST, CascadeType.SAVE_UPDATE, CascadeType.DELETE })
public Set<Employee> getEmployees() {
return employees;
}
public void setEmployees(Set<Employee> employees) {
this.employees = employees;
}
}
[/code]
Employee Class
[code]
@Entity
@Table(name = "Employee")
public class Employee implements Serializable
{
private static final long serialVersionUID = -8732345803771451030L;
private String id;
private String name;
private Employeer employeer;
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name="uuid", strategy="uuid2")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne
@JoinColumn(insertable = true, updatable = true, name = "EmployerID")
public Employeer getEmployeer() {
return employeer;
}
public void setEmployeer(Employeer employeer) {
this.employeer = employeer;
}
}