Troubleshooting Hibernate SessionFactory

My, that’s a snappy title!

I’m still having loads of problems describing the relationships (@OneToMany, @ManyToOne and @OneToOne) between @Entity objects in my Moodle project.

I did a standard install of Moodle to allow it to create the database. I’m now in the process of annotating/modifying the Groovy classes to represent the database. For those unfamiliar with Moodle, it should be noted that the tables created don’t have foreign key constraints. I can only imagine this is done to make the install process work with databases that don’t support the concept.

When I created the @Entity classes I tried to group them into logical packages. This allows me to introduce them gradually by changing the entity-scan.packages entry in application.yml. At the moment only the config package is enable and it works, though it’s only three tables and they have no relationships. As soon as I include a second package I get the session factory error noted in the previous post.

In trying to understand what was failing I enabled trace logging of the org.hibernate.cfg class:

<logger name="org.hibernate.cfg" level="trace"/>

When only the config package is enabled I see this line, which is missing when other packages are enabled.

org.hibernate.cfg.Settings - SessionFactory name : default

When other packages are enabled I see this line in the log:

Binding column: Ejb3JoinColumn{logicalColumnName='null', referencedColumn='null', mappedBy='null'}