-->
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: could not insert in table
PostPosted: Sat Apr 09, 2011 2:28 am 
Newbie

Joined: Sat Apr 09, 2011 2:18 am
Posts: 1
Hi,

I want to insert into square table length,breath and area.. but I am facing problem and getting following error message
Hibernate: insert into Figure (LENGHT, BREATH, AREA, DISCR_COL) values (?, ?, ?, 'Square')
org.hibernate.exception.GenericJDBCException: could not insert: [com.sandeep.Square]

I don't want to create Figure table..all I want data should be inserted in square table only.

Below are the class I created and their hbm.xml file.

Can someone please download this code and set up in their env and help me.

Thanks a ton
----------------------------------------------------------
package com.sandeep;

public abstract class Figure
{
private int id = 0;
private State state = State.abc;

public State getState() {
return state;
}

public void setState(State m_state) {
this.state = m_state;
}


public static final class State
{
public static final State abc = new State();

private State()
{
super();
}
}
}
------------------------------------------------------------------

package com.sandeep;

public class Square extends Figure
{
private int lenght;
private int breath;
private int area;

public Square(int a, int b, int c)
{
this.lenght = a;
this.breath = b;
this.area = c;
setState(State.abc);
}
}
---------------------------------------------------------------------

package com.sandeep;

import org.hibernate.*;
import org.hibernate.cfg.Configuration;

public class SquareClient
{
public static void main(String[] args)
{
try
{
SessionFactory sf = new Configuration().configure("com/sandeep/square.cfg.xml").buildSessionFactory();
Session s1 = sf.openSession();
Square e1 = new Square(100,10,1000);
Transaction t1 = s1.beginTransaction();
s1.save(e1);
t1.commit();
}
catch (Exception e)
{
System.out.println(e);
}
}
}
------------------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 9, 2011 1:38:58 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.sandeep.Figure" abstract="true">
<id name="id" type="int" access="field">
<column name="ID" />
<generator class="native" />
</id>
<discriminator type="string">
<column name="DISCR_COL" />
</discriminator>
<!-- <many-to-one name="m_state" class="com.sandeep.Figure$State" access="field" fetch="join">
<column name="M_STATE" />
</many-to-one> -->
<component name="state" class="com.sandeep.Figure$State">
</component>
</class>
</hibernate-mapping>
----------------------------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 9, 2011 1:38:58 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<subclass name="com.sandeep.Square" extends="com.sandeep.Figure" discriminator-value="Square" lazy="false">
<property name="lenght" type="int" access="field">
<column name="LENGHT" />
</property>
<property name="breath" type="int" access="field">
<column name="BREATH" />
</property>
<property name="area" type="int" access="field">
<column name="AREA" />
</property>
</subclass>
</hibernate-mapping>
----------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">50</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hbm2ddl.auto">update</property>

<!-- Mapping files -->
<mapping resource="com/sandeep/Figure.hbm.xml"/>
<mapping resource="com/sandeep/Square.hbm.xml"/>
</session-factory>
</hibernate-configuration>
-------------------------------------------------------------------------


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.