rxue / dictionary

Practice in Java EE
0 stars 0 forks source link

ditionary/jpa : redesign: trial of unidirectional @OneToMany (1 lexical item to many explanations) #129

Open rxue opened 5 months ago

rxue commented 5 months ago

Got the following DDL generated and executed with pure @OneToMany annotation on LexicalItem#explanations:

Hibernate: create table Explanation (creation_date date, id bigint not null, last_update_time datetime(6), explanation varchar(255) not null, language varchar(255) not null, partOfSpeech enum ('ADJ','N','VI','VT','ADV','PRON','INTERJ'), primary key (id)) engine=InnoDB
Hibernate: create table lexical_item (creation_date date, id bigint not null auto_increment, last_update_time datetime(6), language varchar(255) not null, value varchar(255) not null, primary key (id)) engine=InnoDB
Hibernate: create table lexical_item_Explanation (LexicalItem_id bigint not null, explanations_id bigint not null, primary key (LexicalItem_id, explanations_id)) engine=InnoDB

lexical_item_Explanation table was created for the one-to-many relationship, but it is an extra table :<

rxue commented 5 months ago

encountered error:

org.hibernate.AnnotationException: Collection 'rx.dictionary.jpa.entity.LexicalItem.explanations' is 'mappedBy' a property named 'lexicalItemID' which does not exist in the target entity 'rx.dictionary.jpa.entity.Explanation'
    at org.hibernate.boot.model.internal.CollectionBinder.isReversePropertyInJoin (CollectionBinder.java:1611)
    at org.hibernate.boot.model.internal.CollectionBinder.noAssociationTable (CollectionBinder.java:1625)
    at org.hibernate.boot.model.internal.CollectionBinder.bindStarToManySecondPass (CollectionBinder.java:1586)
    at org.hibernate.boot.model.internal.CollectionBinder$1.secondPass (CollectionBinder.java:1577)
    at org.hibernate.boot.model.internal.CollectionSecondPass.doSecondPass (CollectionSecondPass.java:45)
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses (InFlightMetadataCollectorImpl.java:1815)
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses (InFlightMetadataCollectorImpl.java:1774)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:331)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:1432)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:1503)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory (HibernatePersistenceProvider.java:55)
    at jakarta.persistence.Persistence.createEntityManagerFactory (Persistence.java:80)
    at jakarta.persistence.Persistence.createEntityManagerFactory (Persistence.java:55)
    at rx.dictionary.jpa.Main.main (Main.java:9)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:840)