Note that there are some explanatory texts on larger screens.

plurals
  1. POError perisiting manyToOne relationship that can be null (org.hibernate.TransientObjectException)
    primarykey
    data
    text
    <p>i'm getting exception when i try to persist object Municipio. Municipio has manyTone Relationship to Provincia and another manyToOne relationship to Sector. Provincia can't be null but Sector can be null. I don't know how to allow that Sector can be null because when I try to save object Municipio an Exception is thrown.</p> <pre><code>java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: es.caib.biocides.persistence.Municipio.sector -&gt; es.caib.biocides.persistence.Sector at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:611) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:513) </code></pre> <p>Municipio</p> <pre><code>/** * The persistent class for the BCD_MUNICIPIO database table. * */ @Entity @Table(name="BCD_MUNICIPIO") public class Municipio implements Serializable { @Id @SequenceGenerator(name="BCD_MUNICIPIO_MUNCODIGO_GENERATOR", sequenceName="BCD_MUN_SEQ") @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="BCD_MUNICIPIO_MUNCODIGO_GENERATOR") @Column(name="MUN_CODIGO") private Long munCodigo; @Column(name="MUN_NOMBRE") private String munNombre; //bi-directional many-to-one association to Provincia @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="MUN_CODPRV") private Provincia provincia; //bi-directional many-to-one association to Sector @ManyToOne(fetch=FetchType.LAZY, optional=true) @JoinColumn(name="MUN_CODSEC", nullable=true) private Sector sector; public Municipio() { } public Long getMunCodigo() { return this.munCodigo; } public void setMunCodigo(Long munCodigo) { this.munCodigo = munCodigo; } public String getMunNombre() { return this.munNombre; } public void setMunNombre(String munNombre) { this.munNombre = munNombre; } public Provincia getProvincia() { return this.provincia; } public void setProvincia(Provincia provincia) { this.provincia = provincia; } public Sector getSector() { return this.sector; } public void setSector(Sector sector) { this.sector = sector; } } </code></pre> <p>Sector</p> <pre><code>/** * The persistent class for the BCD_SECTOR database table. * */ @Entity @Table(name="BCD_SECTOR") public class Sector implements Serializable { private static final long serialVersionUID = 1L; @Id @SequenceGenerator(name="BCD_SECTOR_SECCODIGO_GENERATOR", sequenceName="BCD_SEC_SEQ") @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="BCD_SECTOR_SECCODIGO_GENERATOR") @Column(name="SEC_CODIGO") private Long secCodigo; @Column(name="SEC_NOMBRE") private String secNombre; //bi-directional many-to-one association to Municipio @OneToMany(mappedBy="sector") private List&lt;Municipio&gt; municipios; public Sector() { } public Long getSecCodigo() { return this.secCodigo; } public void setSecCodigo(Long secCodigo) { this.secCodigo = secCodigo; } public String getSecNombre() { return this.secNombre; } public void setSecNombre(String secNombre) { this.secNombre = secNombre; } public List&lt;Municipio&gt; getMunicipios() { return this.municipios; } public void setMunicipios(List&lt;Municipio&gt; municipios) { this.municipios = municipios; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload