0

I'm currently migrating a Hibernate implementation to use EntityManager instead of Session. During initialisation, the following stacktrace is dumped:

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: myunit] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:967)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892)
    at com.example.DbConnector.initialize(DbConnector.java:93)
    at com.example.Start.main(Start.java:12)
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:123)
    at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
    at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:128)
    ... 6 more
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:91)
    at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:116)
    at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:385)
    ... 15 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    ... 19 more
Caused by: org.hibernate.PropertyNotFoundException: Could not locate setter method for property [com.example.MyEntity#new]
    at org.hibernate.internal.util.ReflectHelper.findSetterMethod(ReflectHelper.java:552)
    at org.hibernate.property.access.internal.PropertyAccessBasicImpl.<init>(PropertyAccessBasicImpl.java:44)
    at org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl.buildPropertyAccess(PropertyAccessStrategyBasicImpl.java:27)
    ... 26 more

Although this appears to be a common exception (see here and here), the root cause makes no sense in this instance. Normally it's triggered by a missing setter/getter method, but I'm not entirely sure how I would go about creating a setter for new, the constructor.

Here is the contents of com.example.DbConnector.initialize(...):

final Properties props = new Properties();
props.putAll(config);

final List<String> entities = new ArrayList();
entities.add("com.example.MyEntity");

final PersistenceUnitInfo persistenceUnitInfo = new PersistenceUnitInfoImpl("myunit", entities, props);

final PersistenceUnitInfoDescriptor descriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);

final EntityManagerFactoryBuilder emFactoryBuilder = new EntityManagerFactoryBuilderImpl(descriptor, null);

INSTANCE.entityManagerFactory = emFactoryBuilder.build();

What is triggering this exception?


Update: Here's the source of MyEntity:

@Entity
@Table(name = "myEntity")
public class MyEntity extends BaseEntity {
    private String name;

    public MyEntity() {
    }

    public MyEntity(final String name) {
        this.name = name;
    }

    @Basic
    @NaturalId
    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }
}

And of BaseEntity:

@MappedSuperclass
public abstract class BaseEntity {
    protected UUID id;
    protected LocalDateTime created;
    protected LocalDateTime updated;

    @PrePersist
    public void prePersist() {
        preUpdate();
        created = updated;
    }

    @PreUpdate
    public void preUpdate() {
        updated = LocalDateTime.now();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "uuid-generator")
    @GenericGenerator(name = "uuid-generator", strategy = "uuid2")
    @Column(name = "id")
    public UUID getId() {
        return id;
    }

    public void setId(final UUID id) {
        this.id = id;
    }

    @Basic
    @Column(name = "created")
    public LocalDateTime getCreated() {
        return created;
    }

    public void setCreated(final LocalDateTime created) {
        this.created = created;
    }

    @Version
    @Column(name = "updated")
    public LocalDateTime getUpdated() {
        return updated;
    }

    public void setUpdated(final LocalDateTime updated) {
        this.updated = updated;
    }
}
Community
  • 1
  • 1
MTCoster
  • 5,868
  • 3
  • 28
  • 49

0 Answers0