-->
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.  [ 5 posts ] 
Author Message
 Post subject: Error saving entity
PostPosted: Wed Mar 10, 2010 8:44 am 
Newbie

Joined: Wed Mar 10, 2010 8:23 am
Posts: 3
Hello people, i hope someone can help me to workarround this:

I have 14 tables and 14 entities but 13 of them can be saved through session.save(entity) without any problem but one table, here is the SQL.

CREATE TABLE "LAURA2"."CONTABILIDAD_ANYO"
( "ANYO" VARCHAR2(4 CHAR) NOT NULL ENABLE,
"CONTABILIDAD_ID" VARCHAR2(20 CHAR) NOT NULL ENABLE,
"HEREDADA" NUMBER(22,0),
"RESTANTE" NUMBER(22,0),
"TOTAL" NUMBER(22,0),
"GASTADO" NUMBER(22,0),
CONSTRAINT "CONTABILIDAD_A_O_PK" PRIMARY KEY ("ANYO", "CONTABILIDAD_ID"),
CONSTRAINT "CONTABILIDAD_A_O_CONTABIL_FK" FOREIGN KEY ("CONTABILIDAD_ID")
REFERENCES "LAURA2"."CONTABILIDAD" ("ID") ENABLE
)

and so the mapping:

@Entity
@Table(name="CONTABILIDAD_ANYO")
public class ContabilidadAnyo implements Serializable {
private static final long serialVersionUID = 1L;

@EmbeddedId
private ContabilidadAnyoPK id;

private BigDecimal gastado;

private BigDecimal heredada;

private BigDecimal restante;

private BigDecimal total;
.
.
.
}

@Embeddable
public class ContabilidadAnyoPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;

@Column(name="ANYO")
private String anyo;

@Column(name="CONTABILIDAD_ID")
private Contabilidad contabilidadBean;
.
.
.
}

I use an Oracle 10g XE Database with the 10.2.0.4 jdbc driver (I tried the 10.2.0.3 also)

The error message is ORA-01461: can bind a LONG value only for insert into a LONG column

I have tried setting the varchar2 columns with varchar2(char) (as you can see in the sql definition).
Also I tried to set the same encoding as the database has:
<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">al32utf8</property>

All those "solutions" i read at forums can't fix my problem.
When i try to insert the same data at sql developer(cp1252 encoding) there is no problem.

Am i doing something wrong?

Thank you

(I forgot to paste the sql generated by hibernate:
insert into CONTABILIDAD_ANYO (gastado, heredada, restante, total, ANYO, CONTABILIDAD_ID) values (?, ?, ?, ?, ?, ?)
for values (null,null,null,null,'2010','4') )


Last edited by Khanser on Wed Mar 10, 2010 9:08 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Error saving entity
PostPosted: Wed Mar 10, 2010 8:52 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
How did you define class Contabilidad ?


Top
 Profile  
 
 Post subject: Re: Error saving entity
PostPosted: Wed Mar 10, 2010 8:56 am 
Newbie

Joined: Wed Mar 10, 2010 8:23 am
Posts: 3
@Entity
public class Contabilidad implements Serializable {
private static final long serialVersionUID = 1L;

@SequenceGenerator(name = "generator", sequenceName = "CONTABILIDAD_SEQ")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "ID", unique = true, nullable = false, length = 20)
private String id;

private String categoria;

private String proyecto;

@Column(name="TOTAL")
private BigDecimal total;

@Column(name="RESTANTE")
private BigDecimal restante;

@Column(name="GASTADO")
private BigDecimal gastado;

@Column(name="ENTIDAD_FINANCIERA")
private String entidadFinanciera;

//bi-directional many-to-one association to CategoriaContabilidad
@OneToMany(mappedBy="contabilidadBean", fetch=FetchType.EAGER)
private Set<CategoriaContabilidad> categoriaContabilidads;

//bi-directional many-to-one association to Proyecto
@OneToMany(mappedBy="contabilidadBean", fetch=FetchType.EAGER)
private Set<Proyecto> proyectos;

...
}


Top
 Profile  
 
 Post subject: Re: Error saving entity
PostPosted: Wed Mar 10, 2010 9:15 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
@Column(name="CONTABILIDAD_ID")
private Contabilidad contabilidadBean;


Contabilidad is a entity class.
Entity properties cannot be mapped with the @Column annotation,
you must use the @ManyToOne or the @OneToOne annotation instead for mapping entity properties.

What's unusual in your scenario, is that you seem intended to make property contabilidadBean
become part of ContabilidadAnyo's composite primary key.
Im not sure if this is mappable in this way ...


Top
 Profile  
 
 Post subject: Re: Error saving entity
PostPosted: Wed Mar 10, 2010 10:29 am 
Newbie

Joined: Wed Mar 10, 2010 8:23 am
Posts: 3
Thank you! The problem is solved! I can not use a foreign key in a PK so I used a String and everything is fine now.


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

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.