Hibernate ORM modelling composite keys when to insert data into MYSQL

145
April 10, 2018, at 09:11 AM

I am trying to insert data from a csv into a MySQL database maintain relationships between tables.

CSV format:

group1, John, 45, Hockey Fishing Movies
group1, Mary, 28, Dancing Fishing Rugby
group2, Ellen, 18, Fishing Netflix Facebook
group3, Paul, 19, Fishing Facebook Netflix

I have a database schema which looks like:

I have abstracted this example to fit my model and no problems with parsing, database connectivity etc. Purely with modelling this in hibernate and how to correctly perform insertion. Looked a few different hibernate tutorials but have not seen what I am looking for. In terms of modelling this in hibernate, is hibernate the correct approach?

NOTE: only insertion is necessary

Thanks in advance, any help greatly appreciated

Answer 1

Person to Interest looks like many to many relation to me, with person_interest as the mapping table. You can model a bidirectional @ManyToMany relationship like

@Entity
@Table(name = "Person")
public class Person {
    .....
    @ManyToMany
    @JoinTable(
        name = "person_interest ", 
        joinColumns = { @JoinColumn(name = "personId") }, 
        inverseJoinColumns = { @JoinColumn(name = "interestId") }
    )
    private Set<Interest> interests = new HashSet();
    ..... other attributes and getter/setters
}

This is the reverse relation from interest to person.

@Entity
@Table(name = "Interest")
public class Interest{
    .....
    @ManyToMany
    private Set<Person> persons = new HashSet();
    ..... other attributes and getter/setters
}

For further reading.

Rent Charter Buses Company
READ ALSO
Combine the results of two queries into one

Combine the results of two queries into one

I am trying to make the following query in MySQL:

127
Unable to insert data to MySQL using Python and scrapy pipelines

Unable to insert data to MySQL using Python and scrapy pipelines

I have tried hours to get around this but still cannot make it to work properlyI am using scrapy to scrape data from a website and then trying to insert that into MySQL database

144
Assign value from mysql into dict using python

Assign value from mysql into dict using python

If I am only returning one row from my mysql query and I know the headers can I assign those values via dict in python? I do have some data that is nestedThe data will eventually be returned as a JSON object

173
code Igniter Failover Array

code Igniter Failover Array

I'm not needing help with failover connection, just what might be wrong with this failover array? I have tested the alternate db connection and works greatIssue is when I turn off primary, failover does not connect as it should

139