Hibernate - Exception bei insert

y0dA

Erfahrenes Mitglied
Hoi!
Durch den tollen Foren Support war es mir nun endlich möglich Hibernate in ein Beispiel-Projekt einzubinden und in weiterer Folge ein minimales Szenarion zu gestalten. Leider stehe ich nun vor einer kleine Exception welche ich nicht deuten kann.

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
 
ich habe leider jetzt keine zeit deinen code genauer anzusehen, hab jetz gleich meeting und dann gehts nach hause nach österreich langes wochenende!! wee ;)

was ich dir kurz noch anraten würde

wenn das dein erster test ist, nimm eine klasse mit einem attribut her, schau ob du das abspeichern kannst (also nicht so komplex)
eine id + einen string oder so.

überprüfe ob die DB läuft und eine Verbindung hergestellt werden kann, bzw. ob die tabelle schon angelegt wurde

naja, i schau mir das später mal an

mfg
 
Es wurde keine Tabelle angelegt.

Hier der komplette Stacktrace:

24.05.2007 16:56:50 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4
24.05.2007 16:56:50 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
24.05.2007 16:56:50 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
24.05.2007 16:56:50 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
24.05.2007 16:56:50 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
24.05.2007 16:56:50 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
24.05.2007 16:56:50 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : at/pcd/wam/technologie/model/AdvancedAddressModel.hbm.xml
24.05.2007 16:56:50 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: at.pcd.wam.technologie.model.AdvancedAddressModel -> ADVANCED_ADDRESS
24.05.2007 16:56:50 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
24.05.2007 16:56:50 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
24.05.2007 16:56:50 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
24.05.2007 16:56:50 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
24.05.2007 16:56:50 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://mag2;databaseName=spc
24.05.2007 16:56:50 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sa, password=****}
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Microsoft SQL Server, version: 8.00.194
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 1.1.1501.101
24.05.2007 16:56:51 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
24.05.2007 16:56:51 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
24.05.2007 16:56:51 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
24.05.2007 16:56:51 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
24.05.2007 16:56:51 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
24.05.2007 16:56:51 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
24.05.2007 16:56:51 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
24.05.2007 16:56:51 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: null
24.05.2007 16:56:51 org.hibernate.util.JDBCExceptionReporter logExceptions
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:38)
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
 
Es wurde keine Tabelle angelegt.

Ich bin ehrlich gesagt noch nie auf den Gedanken gekommen, mir mit Hibernate direkt eine ganze Tabelle anlegen zu wollen. Bist du sicher, dass das gehen müsste? Ich dachte bislang das wäre nur für die Einträge in den Tabellen gut und man müsste die vorher von Hand anlegen ...
 
ich habe leider jetzt keine zeit deinen code genauer anzusehen, hab jetz gleich meeting und dann gehts nach hause nach österreich langes wochenende!! wee ;)

was ich dir kurz noch anraten würde

wenn das dein erster test ist, nimm eine klasse mit einem attribut her, schau ob du das abspeichern kannst (also nicht so komplex)
eine id + einen string oder so.

überprüfe ob die DB läuft und eine Verbindung hergestellt werden kann, bzw. ob die tabelle schon angelegt wurde

naja, i schau mir das später mal an

mfg

Proko meint doch auch dass das ginge (mit Tabelle anlegen).
 
Also ich sehe an deinem Code keine Fehler. Der Fehler wurde auch von deiner DB ausgelöst und mit der kann ich leider nichts anfangen. :-(

MFG

zEriX
 
Hibernate legt normal die Tabellen selbst an. Du kannst aber mal eine anlegen und dann versuchen ob es funktioniert.
 
Oh Mann was ist dieser SQL Server dämlich -.- hab nun eine Tabelle angelegt und versucht in jene ein Insert zu machen - bekomme wieder diese Fehlermeldung:

24.05.2007 16:56:51 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Wert für Parameternummer "2" wurde nicht festgelegt.

**EDIT**
Kann es sein dass ich alle columns der tabelle in meinem model abbilden muss, selbst wenn ich sie nicht benutze? Weiters ist mein primary key ein identifier und hab dies nun im mapping file angepasst.

Frage:
+) Wofür benötige ich folgendes: discriminator-value="0"
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück