Hey!
Driver (tried both):
jtds-1.2, sqljdbc
Hibernate vers: 3.2.4
I get following exception if I try to insert into db:
Exception:
SCHWERWIEGEND: Parameter #9 has not been set.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [at.pcd.wam.technologie.model.AdvancedAddressModel]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.save(Unknown Source)
at at.pcd.wam.technologie.test.TestHibernate.main(TestHibernate.java:52)
Caused by: java.sql.SQLException: Parameter #9 has not been set.
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareSQL(ConnectionJDBC2.java:602)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:420)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 22 more
interface:
Code:
public interface IGeo {
/** street */
public String street = null;
/** houseNumber */
String houseNumber = null;
/** zip code */
String zip = null;
/** locality */
String locality = null;
/** country */
String country = null;
}
abstract class:
Code:
package at.pcd.wam.technologie.model;
import java.io.Serializable;
import javax.persistence.Transient;
public abstract class AbstractGeoModel implements IGeo, Serializable {
/** street */
protected String street;
/** houseNumber */
protected String houseNumber;
/** zip code */
protected String zip;
/** locality */
protected String locality;
/** country */
@Transient
protected String country;
/**
* transform <code>this</code> into a valid string for geocoding
* @return model data as string - format [street,house,zip,city,country]
*/
public abstract String toString();
/**
* getter method
* @return locality
*/
public String getLocality() {
return this.locality;
}
/**
* setter method
* @param locality locality
*/
public void setLocality(final String locality) {
this.locality = locality;
}
/**
* getter method
* @return country
*/
public String getCountry() {
return this.country;
}
/**
* setter method
* @param country country
*/
public void setCountry(final String country) {
this.country = country;
}
/**
* getter method
* @return houseNumber
*/
public String getHouseNumber() {
return this.houseNumber;
}
/**
* setter method
* @param houseNumber house number
*/
public void setHouseNumber(final String houseNumber) {
this.houseNumber = houseNumber;
}
/**
* getter method
* @return street
*/
public String getStreet() {
return this.street;
}
/**
* setter method
* @param street street
*/
public void setStreet(final String street) {
this.street = street;
}
/**
* getter method
* @return zip
*/
public String getZip() {
return this.zip;
}
/**
* setter method
* @param zip zip code
*/
public void setZip(final String zip) {
this.zip = zip;
}
}
my model:
Code:
package at.pcd.wam.technologie.model;
public class AdvancedAddressModel extends AbstractGeoModel {
/** primary key for database table */
private int id;
/** need for serializable - dynamic serial version UID */
private static final long serialVersionUID = 7999991466190548693L;
/** country code - cc */
private String countryCode;
/** geo coordinate lattidue */
private String geoLat;
/** geo coordinate longitude */
private String geoLong;
/**
* empty constructor
*/
public AdvancedAddressModel() {
//nothin to do
}
/**
* constructor for using fields
* @param street street
* @param houseNumber houseNumber
* @param zip zip code
* @param locality locality
* @param country country
*/
public AdvancedAddressModel(final String street, final String houseNumber, final String zip, final String locality,
final String country) {
this.street = street;
this.houseNumber = houseNumber;
this.zip = zip;
this.locality = locality;
this.country = country;
}
@Override
public String toString() {
return null;
}
/**
* getter method
* @return country code
*/
public String getCountryCode() {
return this.countryCode;
}
/**
* setter method
* @param countryCode country code
*/
public void setCountryCode(final String countryCode) {
this.countryCode = countryCode;
}
/**
* getter method
* @return geoLat geo coordinate lattidude
*/
public String getGeoLat() {
return this.geoLat;
}
/**
* setter method
* @param geoLat geo coordinate lattidude
*/
public void setGeoLat(final String geoLat) {
this.geoLat = geoLat;
}
/**
* getter method
* @return geoLong geo coordinate longitude
*/
public String getGeoLong() {
return this.geoLong;
}
/**
* setter method
* @param geoLong geo coordinate longitude
*/
public void setGeoLong(final String geoLong) {
this.geoLong = geoLong;
}
/**
* getter method
* @return id primary key
*/
public int getId() {
return this.id;
}
/**
* setter method
* @param id primary key
*/
public void setId(final int id) {
this.id = id;
}
}
Mapping:
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 package="at.pcd.wam.technologie.model">
<class name="at.pcd.wam.technologie.model.AdvancedAddressModel" table="I_80050" schema="dbo" catalog="spc">
<!-- primary key -->
<id name="id" type="integer" column="ID" length="30">
<generator class="native"></generator>
</id>
<property name="countryCode" type="string" column="CC"></property>
<property name="geoLat" type="string" column="GEO_LAT"></property>
<property name="geoLong" type="string" column="GEO_LONG"></property>
<property name="street" type="string" column="STRASSE">
<meta attribute="field-description">
without house number.
</meta>
</property>
<property name="zip" type="string" column="PLZ"></property>
</class>
</hibernate-mapping>
main testing class:
Code:
public class TestHibernate {
/**
* @param args
*/
public static void main(String[] args) {
Session session = HibernateUtil.getCurrentSession();
Transaction ta = session.beginTransaction();
ArrayList<AdvancedAddressModel> aModel = (ArrayList<AdvancedAddressModel>)
session.createQuery("select id, countryCode from AdvancedAddressModel").list();
//***
AdvancedAddressModel model = new AdvancedAddressModel();
model.setZip("zip");
model.setCountryCode("country code");
session.saveOrUpdate(model);
ta.commit();
}
}
hibernate.cfg.xml:
Code:
<?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.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="hibernate.connection.password">jhcbxr</property>
<property name="hibernate.connection.url">
jdbc:microsoft:sqlserver://mag2;DatabaseName=sbc
</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">mag2-sa</property>
<property name="connection.url">
jdbc:sqlserver://mag2;databaseName=spc
</property>
<property name="connection.username">sa</property>
<property name="connection.password">jhcbxr</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<mapping
resource="at/pcd/wam/technologie/model/AdvancedAddressModel.hbm.xml" />
</session-factory>
</hibernate-configuration>
best regards