I'm trying to get a simple mapping done but I am having issues.
Basically what I have in Mysql is a User table with just one column that is a varchar(255)
named Username that is the primary key.
I have one other table called notes which has a primary auto-generating key that is an int
, a date
column, varchar
name and contents columns and a varchar(255)
called owner which should contain a user's username.
This is tagged as a foreign key referencing Users (Username).
The code to get the session factory is this:
private static SessionFactory createSessionFactory() {
SessionFactory sessionFactory;
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
configuration.addAnnotatedClass(Note.class);
configuration.addAnnotatedClass(User.class);
StandardServiceRegistry serviceRegistry = new
StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
This works fine without the line that adds the annotated class 'Note' so it is probably an issue with that class. The error is this:
Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister org.hibernate.MappingException
Full stacktrace:
Full classes are available here:
UPDATE: fixed Owner/OwnerName variable misnaming however I now get this error: ERROR:
Cannot add or update a child row: a foreign key constraint fails (
notes
.notes
, CONSTRAINTnotes_ibfk_1
FOREIGN KEY (Owner
) REFERENCESusers
(username
))