Skip to content

NullOrInvalidEntityRule - entity metadata is always null (Kundera mongo 3.12) #1014

@w0rxbend

Description

@w0rxbend

NullOrInvalidEntityRule - metadata is always null

public boolean validate(E entity)
    {
        if (entity != null)
        {
            // entity metadata could be null.
            if (entityMetadata == null)
            {
                throw new IllegalArgumentException(
                        "Entity object is invalid, operation failed. Please check previous log message for details");
            }

            return false;

        }

        // will return false if entity is null.
        return true;
    }

@Data
@Entity
@Table(name = "person", schema = "testDB@defaultPersistenceUnit")
public class Person {

  @Id
  @Column(name = "id")
  private String id;

  private String name;

}

    final EntityManagerFactory defaultPersistenceUnit = Persistence.createEntityManagerFactory("defaultPersistenceUnit");
    final EntityManager entityManager = defaultPersistenceUnit.createEntityManager();
    final Person person = new Person();
    entityManager.persist(person);
    return ok(Json.toJson(person));

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  version="2.1">

  <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>com.impetus.kundera.KunderaPersistence</provider>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="kundera.nodes" value="localhost"/>
      <property name="kundera.port" value="27017"/>
      <property name="kundera.keyspace" value="testDB"/>
      <property name="kundera.dialect" value="mongodb"/>
      <property name="kundera.annotations.scan.package" value="models"/>
      <property name="kundera.ddl.auto.prepare" value="create"/>
      <property name="kundera.client.lookup.class" value="com.impetus.client.mongodb.MongoDBClientFactory"/>
    </properties>
  </persistence-unit>

</persistence>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions