-->
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: [Beginner] hibernate mapping
PostPosted: Fri Dec 10, 2010 1:11 pm 
Newbie

Joined: Fri Dec 10, 2010 12:57 pm
Posts: 1
Hello,
this the first time I use Hibernate. I have a simple table, 2 columns, the primary key is a string. I have written the following mapping:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="it.pippo.imtterminalini.hibernate" schema="PIPPO">
    <class dynamic-insert="true" dynamic-update="true" name="CartellinoEsistito" table="CARTELLINI_ESISTITI">
        <id column="CARTELLINO" name="cartellino" >
            <!generator class="native"/>
        </id>
        <property column="ANCORA_ESISTENTE" name="ancoraEsistente"/>
    </class>
</hibernate-mapping>


and a class:

Code:
package it.pippo.imtterminalini.hibernate;

import java.io.Serializable;

public class CartellinoEsistito implements Serializable
{
    /**
     * This attribute maps to the column CARTELLINO in the CARTELLINI_ESISTITI table.
     */
    protected String cartellino;

    /**
     * This attribute maps to the column ANCORA_ESISTENTE in the CARTELLINI_ESISTITI table.
     */
    protected String ancoraEsistente;

    /**
     * Constructor
     *
     */
    public CartellinoEsistito()
    {
    }
   
    /**
     * Constructor
     *
     */
    public CartellinoEsistito(String cartellino, String ancoraEsistente)
    {
        this.cartellino = cartellino;
        this.ancoraEsistente = ancoraEsistente;
    }
   
    /**
     * Method 'getCartellino'
     *
     * @return java.lang.String
     */
    public java.lang.String getCartellino()
    {
        return cartellino;
    }

    /**
     * Method 'setCartellino'
     *
     * @param cartellino
     */
    public void setCartellino(java.lang.String cartellino)
    {
        this.cartellino = cartellino;
    }


    /**
     * Method 'getAncoraEsistente'
     *
     * @return "S" or "N" java.lang.String
     */
    public java.lang.String getAncoraEsistente()
    {
        return ancoraEsistente;
    }

    /**
     * Method 'setCartellino'
     *
     * @param ancoraEsistente "S" or "N"
     */
    public void setAncoraEsistente(java.lang.String ancoraEsistente)
    {
        this.ancoraEsistente = ancoraEsistente;
    }


}


Then, in java, I generate an object:

Code:
ce = new CartellinoEsistito("ABCDE", "S");
sessioneHb.save(ce);

However, here I get a ConstraintViolationException "could not insert".
Please notice that the only constraint in the table is the primary key, and there is no other row in the table with key "ABCDE".

Thank you in advance.


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.