-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @Many To One Insert NULL Values
PostPosted: Thu Aug 28, 2014 12:26 pm 
Newbie

Joined: Thu Aug 28, 2014 11:18 am
Posts: 2
Hello, i am using Hibernate 3.3.1 GA framework, Java 1.7 version and Postgresql 9.1 database.

Here is my problem : i must insert null values et not null values in a field which has a Unidirectional Relation Many To One and it doesn't work, i get this error :

java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before merging: i2.application.sapc.integration.entities.referentiel.SecteurEntity.

I tried to add the nullable=true option on the field ID_SECTEUR_CHANTIER but i still get the same error.

RestrictionEntity Class :

/**
* Getter pour secteurChantier.
* @return secteurChantier
*/
@JoinColumn(name = "ID_SECTEUR_CHANTIER")
@ManyToOne(targetEntity = SecteurEntity.class)
@Override
@NotFound(action = NotFoundAction.IGNORE)
public Secteur getSecteurChantier() {
return secteurChantier;
}

SecteurEntity Class

/**
* Getter pour axeSecteur.
* @return axeSecteur
*/
@OneToMany(targetEntity = AxeSecteurEntity.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "SECTEUR_ID")
@Cascade({
org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE,
org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.PERSIST,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN
})
@JSON(deserialize = false, serialize = false)
public Set<AxeSecteur> getAxeSecteur() {
if (axeSecteur == null) {
axeSecteur = new HashSet<>();
}
return axeSecteur;
}

AxeSecteurEntity Class

/**
* Getter pour secteur.
* @return secteur
*/
@ManyToOne(fetch = FetchType.LAZY, targetEntity = SecteurEntity.class)
@JoinColumn(name = "SECTEUR_ID")
public Secteur getSecteur() {
return secteur;
}


sapc_restriction table :

CREATE TABLE sapc.sapc_restriction
(
discriminator character varying(50) NOT NULL,
id bigint NOT NULL,
date_creation timestamp without time zone,
datedebut timestamp without time zone,
datefin timestamp without time zone,
date_modification timestamp without time zone,
libelle character varying(255),
ager character varying(255),
axe_externe character varying(255),
axe integer,
departement character varying(255),
gene character varying(255),
levee character varying(255),
mode_exploitation character varying(255),
nombre_voies_gauche integer,
nombre_voies_droite integer,
periode character varying(255),
pr_debut integer,
pr_debut_distance integer,
pr_fin integer,
pr_fin_distance integer,
sens character varying(5),
type_localisation character varying(255),
beneficiaire character varying(255),
beneficiaires_indirect character varying(2000),
date_debut_chantier timestamp without time zone,
date_debut_restriction_2 timestamp without time zone,
date_fin_chantier timestamp without time zone,
date_fin_restriction_2 timestamp without time zone,
demandeur character varying(255),
interventions_autorisees boolean,
nature_traveaux character varying(255),
commentaire character varying(2000),
statut character varying(255),
statut_2 character varying(255),
ext_geom geometry,
id_secteur bigint,
utilisateur_createur_id bigint,
utilisateur_modificateur_id bigint,
transmis_sytadin boolean,
transmis_sirius boolean,
entite_responsable bigint,
entite_responsable_2 bigint,
axe_chantier bigint,
pr_debut_chantier integer,
pr_fin_chantier integer,
sens_chantier character varying(255),
id_secteur_chantier bigint,
date_derniere_transmission_sytadin timestamp without time zone,
date_derniere_transmission_sirius timestamp without time zone,
est_copie boolean,
longue_duree boolean,
id_pgt integer,
arrete_specifique boolean,
CONSTRAINT sapc_restriction_pkey PRIMARY KEY (id ),
CONSTRAINT fk_entite_responsable FOREIGN KEY (entite_responsable)
REFERENCES sapc.sapc_equipe (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_entite_responsable_2 FOREIGN KEY (entite_responsable_2)
REFERENCES sapc.sapc_equipe (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT sapc_createur_fr FOREIGN KEY (utilisateur_createur_id)
REFERENCES sapc.sapc_utilisateur (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT sapc_modificateur_fr FOREIGN KEY (utilisateur_modificateur_id)
REFERENCES sapc.sapc_utilisateur (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT enforce_dims_sapc_restriction CHECK (st_ndims(ext_geom) = 2),
CONSTRAINT enforce_srid_sapc_restriction CHECK (st_srid(ext_geom) = 27572)
)
WITH (
OIDS=FALSE
);


Secteur Table :

CREATE TABLE sapc.sapc_secteur
(
id bigint NOT NULL,
libelle character varying(255),
CONSTRAINT sapc_secteur_pkey PRIMARY KEY (id )
)

Axe Secteur Table :

CREATE TABLE sapc.sapc_axe_secteur
(
id bigint NOT NULL,
axe_id bigint,
secteur_id bigint,
CONSTRAINT sapc_axe_secteur_pkey PRIMARY KEY (id ),
CONSTRAINT sapc_sect_axe_axe_fk FOREIGN KEY (axe_id)
REFERENCES sapc.sapc_axe (id_axe) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE,
CONSTRAINT sapc_sect_axe_sect_fk FOREIGN KEY (secteur_id)
REFERENCES sapc.sapc_secteur (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
)

Here is the input type in the jsp :

<sj:select
dataType="json"
id="listeSecteursChantier"
href="%{urlAjouterDemande}"
emptyOption="true"
onChangeTopics="selectionSectionChantier"
onCompleteTopics="selectionSectionChantier"
label="%{getText('gestion.restrictionType.secteur')}"
name="restrictionDTO.idSecteurChantier"
list="secteursChantier"
listKey="id"
listValue="libelle" />

I tried many operations but it still doesn't work, please help me !! :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.