SessionFactory fails to build if @org.hibernate.annotations.Generated is added to a property

Description

I have 2 entities: User and UserGroup (omitting some code to shorten here..):

The userGroup property is generated at row insertion with a database trigger (this is not my real application but just to render the concept..), so I used @org.hibernate.annotations.Generated(GenerationTime.INSERT) to refresh the entity after a persist().

This behaviour worked fine in Hibernate 3.6.10. Migrating to 4.3.10 or 5.0.0.CR1 does not work anymore, giving this exception:

At first glance, it seems the entity is not found by the factory, but removing the annotation @Generated from userGroup property, makes the sessionfactory building process working again.

Investigating in core hibernate code, brought me to org.hibernate.tuple.entity.EntityMetamodel#create() at line 459 (hibernate 4.3.10, but 5.0.0.CR1 is similar).
Here the EntityMetamodel tries to calculate the numberOfMappedColumns from the association:

The problem here is that the metamodel tries to get the UserGroup entity persister, before it is actually created, and execution flow stops at SessionFactotyImpl:1096 (here the entityPersisters field is actually an empty map):

Removing the @Generated annotations makes the sessionfactory build ok.

Another trick: changing EntityMetamodel, line 459 from:

to

makes the software work again, but I think this is not correct in all cases..

Environment

Hibernate 4.3.10 and 5.0.0.CR1, C3P0-0.9.2.1, Sql Server 2012, Java 7u80, Windows 7 64bit

Status

Assignee

Gail Badner

Reporter

Luca Domenichini

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Blocker
Configure