-->
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.  [ 9 posts ] 
Author Message
 Post subject: All DB number types they are mapped as BigDecimal
PostPosted: Wed May 17, 2006 9:13 am 
Newbie

Joined: Mon May 08, 2006 1:11 pm
Posts: 7
Hi,

Hibernate version 3.1.1
Oracle 10g and XE
Windows XP

I am create the hibernate mapping files and all database number types they should be mapped to BigDecimal, includes types like NUMBER(4), NUMBER(8), NUMBER(14,2), All.


This is not well !!!.

Does some solution exist to this Problem? .

I should can to convert a DB TYPE NUMBER(8) to java.lang.integer, and this Not Work. Why?

Regards.

Sergio.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 9:21 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
will this work?

Code:
<property name="column1" type="java.math.BigDecimal" precision="4"/>
<property name="column2" type="java.math.BigDecimal" precision="8"/>
<property name="column3" type="java.math.BigDecimal" precision="14" scale="2"/>


Top
 Profile  
 
 Post subject: All DB number types they are mapped as BigDecimal
PostPosted: Wed May 17, 2006 9:44 am 
Newbie

Joined: Mon May 08, 2006 1:11 pm
Posts: 7
Yes, this Work, but ...

on their Example:

in DB is NUMBER(4)

If Column1 I want to use it as sequence:
----------------------------------------
...
<id name="Column1" column="ID" access="field" type='java.math.BigDecimal'>
<generator class="sequence">
<param name="sequence">sequence_name</param>
</id>
...


This doesn't work, the error is:
... id.IdentifierGenerationException: this id generator generates long, integer, short or string


AND

I want to convert DB NUMBER(4) to java.lang.integer, and this not work!!!.


Top
 Profile  
 
 Post subject: All DB number types they are mapped as BigDecimal
PostPosted: Wed May 17, 2006 11:30 am 
Newbie

Joined: Mon May 08, 2006 1:11 pm
Posts: 7
The Problem in

Complete Example:
-----------------
In Database:
------------
CREATE TABLE "PRUEBAS"."CPR_CONDIVA"
( "ID" NUMBER(10,0) NOT NULL ENABLE,
"DESCRIPCION" VARCHAR2(35 BYTE),
CONSTRAINT "CPR_CONDIVA_PK" PRIMARY KEY ("ID") ENABLE
) ;

The Trigger:
------------
CREATE OR REPLACE TRIGGER "PRUEBAS"."CPR_CONDIVA_TRG" BEFORE INSERT ON CPR_CONDIVA FOR EACH ROW
BEGIN
IF :NEW.ID IS NULL THEN
SELECT CPR_CONDIVA_SEQ.NEXTVAL INTO :NEW.ID
FROM SYS.DUAL;
END IF;
END;


The Sequence:
-------------
CREATE SEQUENCE "PRUEBAS"."CPR_CONDIVA_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ;

File Condiva.xml:
-----------------
<property name="idX" type="java.math.BigDecimal" precision="10"/>
<property name="descripcionX" type="java.lang.string" precision="35"/>

File Condiva.hbm.xml:
---------------------
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="org.openxava.contaduria.modelo">

<class
name="Condiva"
table="CPR_CONDIVA">
<id name="idX" column="ID" access="field" type='java.math.BigDecimal'>
<generator class="sequence">
<param name="sequence">CPR_CONDIVA_SEQ</param>
</generator>
</id>
<property name="descripcionX" column="DESCRIPCION" access="field" type='java.lang.String'/>
</class>

</hibernate-mapping>


In Insert Record, Fail, The Error:
----------------------------------

17/05/2006 12:46:32 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
[ModuleManager.execute] List.viewDetail=11218 ms
Imposible internacionalizar elemento con id Contaduria.Condicioniva
Imposible internacionalizar elemento con id Condiva.view.descripcionX
Imposible internacionalizar elemento con id Condiva.view.descripcionX
[ModuleManager.execute] CRUD.new=16 ms
Imposible internacionalizar elemento con id Contaduria.Condicioniva
Imposible internacionalizar elemento con id Condiva.view.descripcionX
Imposible internacionalizar elemento con id Condiva.view.descripcionX
org.hibernate.id.IdentifierGenerationException: this id generator generates long
, integer, short or string
at org.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFa
ctory.java:59)

at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:78
)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId
(AbstractSaveEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGene
ratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrR
equestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTran
sient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpda
te(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:534)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:522)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.openxava.model.impl.HibernatePersistenceProvider.create(Hibernate
PersistenceProvider.java:120)
at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:578)
at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:40)
at org.openxava.model.MapFacade.create(MapFacade.java:73)
at org.openxava.actions.SaveAction.execute(SaveAction.java:24)
at org.openxava.controller.ModuleManager.executeAction(ModuleManager.jav
a:271)
at org.openxava.controller.ModuleManager.executeAction(ModuleManager.jav
a:212)
at org.openxava.controller.ModuleManager.execute(ModuleManager.java:192)

at org.apache.jsp.xava.module_jsp._jspService(module_jsp.java:304)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
14)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Thread.java:595)
javax.ejb.CreateException: Imposible crear objeto persistente Condiva por: this
id generator generates long, integer, short or string
at org.openxava.model.impl.HibernatePersistenceProvider.create(Hibernate
PersistenceProvider.java:125)
at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:578)
at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:40)
at org.openxava.model.MapFacade.create(MapFacade.java:73)
at org.openxava.actions.SaveAction.execute(SaveAction.java:24)
at org.openxava.controller.ModuleManager.executeAction(ModuleManager.jav
a:271)
at org.openxava.controller.ModuleManager.executeAction(ModuleManager.jav
a:212)
at org.openxava.controller.ModuleManager.execute(ModuleManager.java:192)

at org.apache.jsp.xava.module_jsp._jspService(module_jsp.java:304)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
14)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Thread.java:595)
javax.ejb.CreateException: Imposible crear Condiva
at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:597)
at org.openxava.model.impl.MapFacadeBean.create(MapFacadeBean.java:40)
at org.openxava.model.MapFacade.create(MapFacade.java:73)
at org.openxava.actions.SaveAction.execute(SaveAction.java:24)
at org.openxava.controller.ModuleManager.executeAction(ModuleManager.jav
a:271)
at org.openxava.controller.ModuleManager.executeAction(ModuleManager.jav
a:212)
at org.openxava.controller.ModuleManager.execute(ModuleManager.java:192)

at org.apache.jsp.xava.module_jsp._jspService(module_jsp.java:304)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
14)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Thread.java:595)
[ModuleManager.execute] CRUD.save=4704 ms
Imposible internacionalizar elemento con id Contaduria.Condicioniva

...

Do you understand the Problem?.

As I solve it? .


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 11:51 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I havent used anytime a generator for primary key fields. So at this time couldnt give back any comment.

Meanwhile, change your property element

<property name="descripcionX" type="java.lang.string" precision="35"/>

to

<property name="descripcionX" type="java.lang.string" length="35"/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 11:56 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I still wonder how can this sequence CPR_CONDIVA_SEQ can return you a decimal. Maybe you should go with java.lang.Long type.


Top
 Profile  
 
 Post subject: All DB number types they are mapped as BigDecimal
PostPosted: Wed May 17, 2006 1:08 pm 
Newbie

Joined: Mon May 08, 2006 1:11 pm
Posts: 7
No,

My Sequence return value Long

but,

the idX container is BigDecimal, and alone it works BigDecimal for All DB NUMBER Type.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 1:15 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Maybe you should implement UserType. See this link for examples http://www.hibernate.org/169.html


Top
 Profile  
 
 Post subject: Re: All DB number types they are mapped as BigDecimal
PostPosted: Wed May 17, 2006 7:10 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
saamondino wrote:
Hi,

Hibernate version 3.1.1
Oracle 10g and XE
Windows XP

I am create the hibernate mapping files and all database number types they should be mapped to BigDecimal, includes types like NUMBER(4), NUMBER(8), NUMBER(14,2), All.


This is not well !!!.

Does some solution exist to this Problem? .

I should can to convert a DB TYPE NUMBER(8) to java.lang.integer, and this Not Work. Why?

Regards.

Sergio.


Are you using middlegen to create these mappings? You can control the type of ID that is generated. You should use Long for a Number(8)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.