Hoi!
Driver (hab es mit beiden probiert und klappt nicht):
jtds-1.2, sqljdbc
Hibernate vers: 3.2.4
Ich habe ein Problem mit Hibernate in Bezug auf SQL Server 2005, im Detail bekomme ich folgende Exception sofern ich etwas inserten möchte:
Exception:
SCHWERWIEGEND: Wert für Parameternummer "9" wurde nicht festgelegt.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [at.pcd.wam.technologie.model.AdvancedAddressModel]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
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:30)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Wert für Parameternummer "9" wurde nicht festgelegt.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.buildParamTypeDefinitions(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PreparedStatementExecutionRequest.executeStatement(Unknown Source)
at com.microsoft.sqlserver.jdbc.CancelableRequest.execute(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeRequest(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 22 more
mein 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="AdvancedAddressModel" table="ADVANCED_ADDRESS">
<meta attribute="class-description">
advanced address model.
</meta>
<!-- primary key -->
<id name="id" type="integer" column="ID">
<generator class="native"></generator>
</id>
<!-- fields -->
<property name="country" type="string" column="COUNTRY"></property>
<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="houseNumber" type="string" column="HOUSE_NUMBER"></property>
<property name="locality" type="string" column="LOCALITY"></property>
<property name="street" type="string" column="STREET">
<meta attribute="field-description">
without house number.
</meta>
</property>
<property name="zip" type="string" column="ZIP_CODE"></property>
</class>
</hibernate-mapping>
main klasse:
Code:
package at.pcd.wam.technologie.test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import at.pcd.wam.technologie.hibernate.utility.HibernateUtil;
import at.pcd.wam.technologie.model.AdvancedAddressModel;
public class TestHibernate {
/**
* @param args
*/
public static void main(String[] args) {
Session session = HibernateUtil.getCurrentSession();
Transaction ta = session.beginTransaction();
AdvancedAddressModel model = new AdvancedAddressModel();
model.setId(1);
model.setCountry("Austria");
model.setGeoLat("lattidude");
model.setGeoLong("longitude");
model.setHouseNumber("34");
model.setLocality("locality");
model.setStreet("street");
model.setZip("zip");
model.setCountryCode("country code");
session.save(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>
mfg