ciao ecco
codice:
Exception in thread "main" org.hibernate.PropertyValueException: not-null property references a null or transient value: hibernate.Artista.cognome
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:100)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:312)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
at test.test.main(test.java:52)
e le altre entita coinvolte
codice:
package hibernate;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name = "materialeMultimedialeFilm")
public class MaterialeMultimedialeFilm {
public MaterialeMultimedialeFilm () {
}
//mysql non supporta il sequencegenerator
private long id ;
private String titolo ;
private String regista ;
private List <Artista> attori ; // inteso come scrittori-autori
private int annoDiPubblicazione ;
private int durata ; // in min
private String formato ; // dvd,dvix,mpg
private int valutazione ;
private String genere ;
private String doveSiTrova ;
private String note ;
//======METODI GETTER SETTER=======================
@Column(name = "valutazione" ,nullable = true)
public int getValutazione (){
return valutazione ;
}
public void setValutazione (int valutazione){
this.valutazione= valutazione ;
}
@Column(name = "note" ,nullable = true)
public String getNote (){
return note ;
}
public void setNote (String note){
this.note=note;
}
@Column(name = "formato" ,nullable = false)
public String getFormato (){
return formato ;
}
public void setFormato (String formato){
this.formato=formato;
}
@Column(name = "doveSiTrova" ,nullable = false)
public String getDoveSiTrova (){
return doveSiTrova ;
}
public void setDoveSiTrova (String doveSiTrova){
this.doveSiTrova=doveSiTrova;
}
@Column(name = "annoDiPubblicazione" ,nullable = false)
public int getAnnoDiPubblicazione (){
return annoDiPubblicazione ;
}
public void setAnnoDiPubblicazione (int annoDiPubblicazione){
this.annoDiPubblicazione= annoDiPubblicazione ;
}
@Column(name = "durata" ,nullable = false)
public int getDurata (){
return durata ;
}
public void setDurata (int durata){
this.durata=durata ;
}
@Column(name = "titolo" ,nullable = false)
public String getTitolo (){
return titolo ;
}
public void setTitolo (String titolo){
this.titolo=titolo;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public long getId (){
return id ;
}
public void setId (long id){
this.id= id ;
}
@Column(name = "regista" ,nullable = true)
public String getRegista (){
return regista ;
}
public void setRegista (String regista){
this.regista=regista;
}
@Column(name = "genere" ,nullable = false)
public String getGenere (){
return genere;
}
public void setGenere (String genere){
this.genere=genere;
}
@ManyToMany(fetch = FetchType.LAZY)
public List <Artista> getAttori (){
return attori;
}
public void setAttori (List <Artista> attori ){
this.attori=attori;
}
}
codice:
package hibernate;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "materialeTestuale",
uniqueConstraints =
{
@UniqueConstraint(columnNames = {"titolo" , "annoDiPubblicazione"} ) } )
public class MaterialeTestuale {
public MaterialeTestuale (){
}
//mysql non supporta il sequencegenerator
private long id ;
private String titolo ;
private String genere ;
private int valutazione ;
private int numeroPagine ;
private String doveSiTrova ;
private int annoDiPubblicazione;
private String casaEditrice;
private List <Artista> artisti ; // inteso come scrittori-autori
private String formato ; // pdf ,carta,ect
private String note ;
//======METODI GETTER SETTER=======================
@Column(name = "titolo" ,nullable = false)
public String getTitolo (){
return titolo ;
}
public void setTitolo (String titolo){
this.titolo=titolo;
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
public long getId (){
return id ;
}
public void setId (long id){
this.id= id ;
}
@Column(name = "note" ,nullable = true)
public String getNote (){
return note ;
}
public void setNote (String note){
this.note=note;
}
@Column(name = "valutazione" ,nullable = true)
public int getValutazione (){
return valutazione ;
}
public void setValutazione (int valutazione){
this.valutazione= valutazione ;
}
@Column(name = "numeroPagine" ,nullable = false)
public int getNumeroPagine (){
return numeroPagine ;
}
public void setNumeroPagine (int numeroPagine){
this.numeroPagine= numeroPagine ;
}
@Column(name = "annoDiPubblicazione" ,nullable = false)
public int getAnnoDiPubblicazione (){
return annoDiPubblicazione ;
}
public void setAnnoDiPubblicazione (int annoDiPubblicazione){
this.annoDiPubblicazione= annoDiPubblicazione ;
}
@Column(name = "casaEditrice" ,nullable = true)
public String getCasaEditrice (){
return casaEditrice ;
}
public void setCasaEditrice (String casaEditrice){
this.casaEditrice=casaEditrice;
}
@Column(name = "doveSiTrova" ,nullable = false)
public String getDoveSiTrova (){
return doveSiTrova ;
}
public void setDoveSiTrova (String doveSiTrova){
this.doveSiTrova=doveSiTrova;
}
@Column(name = "formato" ,nullable = false)
public String getFormato (){
return formato ;
}
public void setFormato (String formato){
this.formato=formato;
}
@Column(name = "genere" ,nullable = false)
public String getGenere (){
return genere;
}
public void setGenere (String genere){
this.genere=genere;
}
@ManyToMany(fetch = FetchType.LAZY)
public List <Artista> getArtisti (){
return artisti;
}
public void setArtisti (List <Artista> artisti ){
this.artisti=artisti;
}
}