Hibernate JAVAFX HibernateTool

Hello, i hope i do not ask at the wrong place.

Well, i’m using Hibernate with Java (on eclipse) and i’m trying to reach some field of my database. I used Hibernate tool for the mapping

For example this one of a manyToMany

Can anyone explain me how i can set a value to this field ? (To save in the database after) because when i type Person.set XXX it doesn’t appears as it’s in another entity (not 1-1 but 0,n).

Hope i have been clear enough.

Thank you in advance

I have no idea what you mean by that. Entities are just like normal Java classes and many-to-many associations are modeled as collections, so your model probably has something like this:

class Person {
    @ManyToMany(cascade = ALL)
    @JoinTable(name = "reunion")
    Set<FamilyReunion> reunions;
}

so in order to add something, you need to add an element to that collection.

Hello,

Thank you for your answer.

Well for now i can only access Person field and 1-1 relationship.

Once i try to do : Person.setFamilyReunionType it doesn’t works

Here a part of the mapping done by Hibernate Tool, not enterly (cannot type the @ here it says i try to mention too much people)

Thank you in advance

/**
*Familyreunion generated by hbm2java
*/
Entity
Table(name = “familyreunion”, catalog = “jobway”)
public class Familyreunion implements java.io.Serializable {

private Integer idFamilyReunion;
private String familyReunionType;
private Set persons = new HashSet(0);

public Familyreunion() {
}

public Familyreunion(String familyReunionType) {
this.familyReunionType = familyReunionType;
}

public Familyreunion(String familyReunionType, Set persons) {
this.familyReunionType = familyReunionType;
this.persons = persons;
}

Id
GeneratedValue(strategy = IDENTITY)

Column(name = “idFamilyReunion”, unique = true, nullable = false)
public Integer getIdFamilyReunion() {
return this.idFamilyReunion;
}

public void setIdFamilyReunion(Integer idFamilyReunion) {
this.idFamilyReunion = idFamilyReunion;
}

Column(name = “FamilyReunionType”, nullable = false, length = 50)
public String getFamilyReunionType() {
return this.familyReunionType;
}

public void setFamilyReunionType(String familyReunionType) {
this.familyReunionType = familyReunionType;
}

ManyToMany(fetch = FetchType.LAZY, mappedBy = “familyreunions”)
public Set getPersons() {
return this.persons;
}

public void setPersons(Set persons) {
this.persons = persons;
}

}

Entity
Table(name = “person”, catalog = “jobway”)
public class Person implements java.io.Serializable {

private Integer idPerson;
private Civilstatus civilstatus;
private Country countryByIdCountry;
private Country countryByIdCountrySpouseNationality;
private Guardmean guardmean;
private Household household;
private Situationterritory situationterritory;
private Worksearch worksearch;
private String personFirstName;
private String personLastName;
private String personNiss;
private String personAdress;
private String personPhone;
private Date personBirthDate;
private String personMail;
private String personGender;
private Date personArrivalDate;
private Boolean personHealthcare;
private boolean personNewsLetterWork;
private int personUnemployementDuration;
private Date personForemInsDate;
private String personOrientation;
private boolean personIsDelete;
private Set locomotionmeans = new HashSet(0);
private Set perFors = new HashSet(0);
private Set incometypes = new HashSet(0);

Once i try to do : Person.setFamilyReunionType it doesn’t works

Because that is not how you add elements to a collection. You have to use:

Person p = ...
p.getFamilyReunion().add(new FamilyReunion("your-reunion-type"));

It seems to me that you should first try to understand how basic Java works and how you can work with collections before you start using Hibernate. There are many more things you might run into which you won’t understand unless you have a solid knowledge about Java.