-->
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.  [ 2 posts ] 
Author Message
 Post subject: IllegalArgumentException occurred calling getter of...
PostPosted: Wed Oct 17, 2007 3:39 am 
Newbie

Joined: Wed Oct 17, 2007 3:31 am
Posts: 2
Hallo!

Ich versuche gerade meine erste Anwendung mit Hibernate zum Laufen zu
bekommen. Es gibt eigentlich nur 2 Tables. In der Ersten wird nur eine
ID und ein TEXT gespeichert. In der Zweiten werden mehrere Daten zu
den in der ersten Table erstellten Einträgen gespeichert:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="alisha.Month" table="MONTH">
        <id name="id" column="ID">
            <generator class="native"/>
        </id>
        <property name="text" column="TEXT" type="string"/>
    </class>
</hibernate-mapping>

Code:
package alisha;

public class Month {

    private int id;
    private String text;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="alisha.BookingRow" table="BOOKINGROW">
        <id name="id" column="ID">
            <generator class="native"/>
        </id>
        <many-to-one name="idMonth" column="ID_MONTH"
class="alisha.Month"/>
        <property name="date" column="DATE" type="date"/>
        <property name="text" column="TEXT" type="string"/>
        <property name="proceeds" column="PROCEEDS" type="double"/>
        <property name="expenditure" column="EXPENDITURE"
type="double"/>
        <property name="preTax" column="PRETAX" type="double"/>
        <property name="salesTax" column="SALESTAX" type="double"/>
    </class>
</hibernate-mapping>

Code:
package alisha;

import java.util.Date;

public class BookingRow {

    private int id;
    private int idMonth;
    private Date date;
    private String text;
    private double proceeds;
    private double expenditure;
    private double preTax;
    private double salesTax;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getIdMonth() {
        return idMonth;
    }

    public void setIdMonth(int idMonth) {
        this.idMonth = idMonth;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public double getProceeds() {
        return proceeds;
    }

    public void setProceeds(double proceeds) {
        this.proceeds = proceeds;
    }

    public double getExpenditure() {
        return expenditure;
    }

    public void setExpenditure(double expenditure) {
        this.expenditure = expenditure;
    }

    public double getPreTax() {
        return preTax;
    }

    public void setPreTax(double preTax) {
        this.preTax = preTax;
    }

    public double getSalesTax() {
        return salesTax;
    }

    public void setSalesTax(double salesTax) {
        this.salesTax = salesTax;
    }
}


Wenn ich nun versuche Daten in die erste Tabelle zu schreiben, dann
funktioniert das problemlos. Ich habe das Ergebnis auch mit einem
SQL-Client geprüft.

Wenn ich nun aber versuche Daten in die zweite Tabelle zu schreiben,
dann kommt folgende Ausgabe:

***
init:
deps-jar:
compile:
run:
INFO - Hibernate 3.2.5
INFO - hibernate.properties not found
INFO - Bytecode provider name : cglib
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Reading mappings from resource : BookingRow.hbm.xml
INFO - Mapping class: alisha.BookingRow -> BOOKINGROW
INFO - Reading mappings from resource : Month.hbm.xml
INFO - Mapping class: alisha.Month -> MONTH
INFO - Configured SessionFactory: null
INFO - Using Hibernate built-in connection pool (not for production
use!)
INFO - Hibernate connection pool size: 1
INFO - autocommit mode: false
INFO - using driver: org.h2.Driver at URL:
jdbc:h2:file:./h2Data/alisha
INFO - connection properties: {user=sa, password=****}
INFO - RDBMS: H2, version: 1.0.59 (2007-10-03)
INFO - JDBC driver: H2 JDBC Driver, version: 1.0.59 (2007-10-03)
INFO - Using dialect: org.hibernate.dialect.H2Dialect
INFO - Using default transaction strategy (direct JDBC transactions)
INFO - No TransactionManagerLookup configured (in JTA environment,
use of read-write or transactional second-level cache is not
recommended)
INFO - Automatic flush during beforeCompletion(): disabled
INFO - Automatic session close at end of transaction: disabled
INFO - JDBC batch size: 15
INFO - JDBC batch updates for versioned data: disabled
INFO - Scrollable result sets: enabled
INFO - JDBC3 getGeneratedKeys(): enabled
INFO - Connection release mode: auto
INFO - Default batch fetch size: 1
INFO - Generate SQL with comments: disabled
INFO - Order SQL updates by primary key: disabled
INFO - Order SQL inserts for batching: disabled
INFO - Query translator:
org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO - Using ASTQueryTranslatorFactory
INFO - Query language substitutions: {}
INFO - JPA-QL strict compliance: disabled
INFO - Second-level cache: enabled
INFO - Query cache: disabled
INFO - Cache provider: org.hibernate.cache.NoCacheProvider
INFO - Optimize cache for minimal puts: disabled
INFO - Structured second-level cache entries: disabled
INFO - Echoing all SQL to stdout
INFO - Statistics: disabled
INFO - Deleted entity synthetic identifier rollback: disabled
INFO - Default entity-mode: pojo
INFO - Named query checking : enabled
INFO - building session factory
INFO - Not binding factory to JNDI, no JNDI name configured
INFO - Running hbm2ddl schema export
INFO - exporting generated schema to database
INFO - schema export complete
Hibernate: insert into MONTH (ID, TEXT) values (null, ?)
Hibernate: insert into MONTH (ID, TEXT) values (null, ?)
Hibernate: insert into MONTH (ID, TEXT) values (null, ?)
ERROR - IllegalArgumentException in class: alisha.Month, getter method
of property: id
Exception in thread "main" java.lang.RuntimeException:
IllegalArgumentException occurred calling getter of alisha.Month.id
at alisha.Main.addBookingRow(Main.java:93)
at alisha.Main.main(Main.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 6 seconds)
***

Ich habe schon einige Stunden damit verbracht, zu versuchen, die
Mapping-Dateien richtig hinzubekommen. Einfache Beispiele habe ich
nämlich nicht gefunden. Lt. SQL-Client stimmt aber die Struktur der
automatisch durch Hibernate erstellten Datenbank (Tabellen).

Kann mir bitte jemand einen Tipp geben?

Danke,
Christian.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 9:46 am 
Newbie

Joined: Wed Oct 17, 2007 3:31 am
Posts: 2
Hallo!

Nach längerer Suche, und mit Hilfe der Leseprobe von http://www.galileocomputing.de/katalog/buecher/titel/gp/titelID-978?GalileoSession=88168612A3-qK5Jbcl4 konnte ich das Problem nun selbst lösen. Ich habe mir das Buch auch gleich gekauft.

Mein Datenbank- und Mapping-Design war komplett falsch. Ich habe es nun anhand des Beispieles und meinen Anforderungen umgeschrieben, und nun funktioniert das Ganze einwandfrei.

Jetzt muss ich nur noch den Rest in den Griff bekommen ;-)

Gruß,
Christian.


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