-->
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: Mapping von BigDecimal mit Annotations
PostPosted: Fri Nov 11, 2005 12:40 pm 
Newbie

Joined: Fri Nov 11, 2005 12:29 pm
Posts: 3
Hibernate version:

hibernate 3.1rc1, hibernate annotations 3.1 beta 6

Mapping documents:

annotations

Full stack trace of any exception that occurs:

Building SessionFactory failed: Could not determine type for: company.product.modules.backoffice.Vat, for columns: [org.hibernate.mapping.Column(vat)]
org.hibernate.MappingException: Could not determine type for: company.product.modules.backoffice.Vat, for columns: [org.hibernate.mapping.Column(vat)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:184)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:371)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:975)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1139)
at company.product.core.HibernateUtil.init(HibernateUtil.java:121)
at company.product.core.HibernateUtil.checkForInit(HibernateUtil.java:166)
at company.product.core.HibernateUtil.getSessionFactory(HibernateUtil.java:146)
at company.product.core.Product.<init>(Product.java:80)
at company.product.core.Product.init(Product.java:140)
at company.product.web.AdminServlet.init(AdminServlet.java:210)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:750)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:130)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)

Name and version of the database you are using:

MySQL 4.1.14-nt-log


Hallo zusammen,

ich arbeite jetzt schon einige Zeit mit Hibernate für meine neue WebShop Lösung. Ich arbeite mit Annotations und das funktioniert auch eigentlich wunderbar.

Ich habe bisher bei Fliesskommazahlen immer mit doubles gearbeitet, stosse momentan aber massiv auf rundungsprobleme (1.1 = 1.1000000001) was bei rechnungen usw. unschön aussieht.

Deswegen möchte ich gerade auf BigDecimal umschalten, in der Featureliste unter http://www.hibernate.org wird das als mapping-fähig deklariert.

Ich habe die Klasse Vat, die eine Steuerklasse repräsentieren soll.
Es gibt die drei Steuerklassen Normal (noch! 16%), Ermässigt (7% für bücher etc.) und 0 % (Briefmarken)

Ich erstelle meine Annotation Configuration selbst, also mit:
Code:
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.addAnnotatedClass(company.product.modules.backoffice.Vat.class);
cfg.setProperty("hibernate.connection.datasource", "java:comp/env/" + config.getSqlenv());
cfg.setProperty("hibernate.show_sql", "true");
cfg.setProperty("hibernate.query.substitutions", "true 1, false 0");           cfg.setProperty("hibernate.cglib.use_reflection_optimizer", "true");
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
sessionFactory = cfg.buildSessionFactory();


hier ist die Vat - Klasse:
Code:
package company.product.modules.backoffice;

import company.product.web.WebBean;

import java.math.BigDecimal;

import javax.persistence.*;

import org.hibernate.annotations.Type;

@Entity
@Table(name="backoffice_vatgroups")
public class Vat implements WebBean
{
    protected int id;
    protected String name;
    protected BigDecimal vat;
   
    @Id(generate=GeneratorType.AUTO)
    public Integer getId()
    {
        return id;
    }
   
    public void setId(int id)
    {
        this.id = id;
    }
   
    public String getName()
    {
        return name;
    }
   
    public void setName(String name)
    {
        this.name = name;
    }
   
    @Type(type="java.math.BigDecimal")
    public BigDecimal getVat()
    {
        return vat;
    }
   
    public void setVat(BigDecimal vat)
    {
        this.vat = vat;
    }
   
    @Transient
    public String getIdent()
    {
        return name + " " + getVat().toString() + "%";
    }
}



ich habe mit der @Type annotation schon versucht das irgendwie zu fixen, aber die fehlermeldung bleibt:

Caused by: org.hibernate.MappingException: Could not determine type for: company.product.modules.backoffice.Vat, for columns: [org.hibernate.mapping.Column(vat)]

Ist BigDecimal von Annotations noch nicht unterstützt? oder ist BigDecimal mit einer AnnotationConfiguration ohne hibernate.xml nicht möglich? oder habe ich einfach nur die falsche annotation für getVat() verwendet?

Bin für jede hilfe dankbar

grüße
-- felix


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.