Hibernate - Exception bei insert

Jo nur generiere ich ja kein Statement mittels createQuery() sondern mache einfach immer ein session.save(meinModel) und hierbei tritt dann auch gleich die Exception auf - somit weiß ich leider nicht ganz genau wie ich gewünschtes anstellen soll. Meinst ich soll mittels createQuery() das Insert machen?

btw. danke für deine Mühen ;)

**EDIT**
Hab nun ein Insert abgesetzt:
session.createSQLQuery("INSERT INTO AdvancedAddressModel (street) values (" + model.getStreet() + ")");

Nur scheint es keine Änderung in der DB zu geben.

Stacktrace:
29.05.2007 09:27:44 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4
29.05.2007 09:27:44 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
29.05.2007 09:27:44 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
29.05.2007 09:27:44 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
29.05.2007 09:27:44 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: hibernate.cfg.xml
29.05.2007 09:27:44 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: hibernate.cfg.xml
29.05.2007 09:27:45 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : at/pcd/wam/technologie/model/AdvancedAddressModel.hbm.xml
29.05.2007 09:27:45 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: at.pcd.wam.technologie.model.AdvancedAddressModel -> I_80050_SAVE
29.05.2007 09:27:45 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
29.05.2007 09:27:45 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
29.05.2007 09:27:45 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
29.05.2007 09:27:45 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
29.05.2007 09:27:45 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://mag2;databaseName=spc
29.05.2007 09:27:45 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sa, password=****}
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Microsoft SQL Server, version: 8.00.194
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 1.1.1501.101
29.05.2007 09:27:45 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
29.05.2007 09:27:45 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
29.05.2007 09:27:45 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
29.05.2007 09:27:45 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
29.05.2007 09:27:45 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
29.05.2007 09:27:45 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
29.05.2007 09:27:46 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: spc.dbo.I_80050_SAVE
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [nichtdeutsch, nrid5, spam, zuname, strasse, aenderung, rid4, anforderung, geo_lat, rid2, geo_y, vorname, id, beschreibung, web, rid3, geschlecht, skype, erstellt, geo_x, ort, organisation, titel, funktion, mobiltel, gueltig, htmlmail, cc, geburtsdatum, geo_long, ear, rid1, n_rekey01, plz, telefon, bahnhof, geo, guid, email, review]
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: []
29.05.2007 09:27:46 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete

**EDIT2**
Code:
AdvancedAddressModel model = new AdvancedAddressModel();
		model.setGeoLat("mpfTest");
		model.setGeoLong("mpfTest");
//		model.setLocality("mpfTest");
		model.setStreet("abcd");
		model.setZip("mpfTest");
		model.setCountryCode("mpfTest mpfTest");
		
		SQLQuery v = session.createSQLQuery("INSERT INTO AdvancedAddressModel (street) values ('" + model.getStreet() + "')");
//		session.save(model);
		
		tx.commit();
v = SQLQueryImpl(INSERT INTO AdvancedAddressModel (street) values ('abcd'))
 
Zuletzt bearbeitet:
Hallo,

Java:
package de.tutorials.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class TestHibernate {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Configuration configuration = new Configuration().configure();
		configuration.setProperty("hibernate.show_sql", "true");
		SchemaExport export = new SchemaExport(configuration);
		export.create(false, true);
		SessionFactory factory = configuration.buildSessionFactory();
		Session session = factory.openSession();
		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);
		
		model = null;
		
		
		ta.commit();
		
		model = (AdvancedAddressModel)session.load(AdvancedAddressModel.class, 1);
		System.out.println(model.getCountry());
	}

}

Versuch mal diese Code. Der funktioniert. Hab ich nicht mit HSQLDB getestet.

MFG

zEriX
 
Hab den Code getestet - selber Fehlermeldung, deshalb nun noch einmal meine Frage:
Tabelle TabelleA: Spalten: spalte a, spalte b, spalte c, ...

Mein Model besitzt aber nur spalte a und spalte b.

Nun möchte ich ein Insert machen und setze Werte für spalte a und spalte b --> spalte c fehlt und deshalb Exception? Sprich ich muss alle Spalten der Tabelle abbilden?

mfg
 
Muss man normal schon. Führe bitte nochmal den Code von mir aus und poste die Ausgabe von Hibernate, aber nur die SQL-Statements. Die müssten jetzt mit ausgegeben werden.

MFG

zEriX
 
Füge das hier mal nachher in deine config-File von hibernate ein. Damit müsste die Tabelle automatisch angelegt werden.

Code:
<property name="hibernate.hbm2dll.auto">
			create
		</property>

MFG

zEriX
 
Wie gesagt ich möchte keine Tabelle anlegen - die existiert schon!

hier der Stacktrace zu deinem code:
29.05.2007 10:39:01 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.4
29.05.2007 10:39:01 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
29.05.2007 10:39:01 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
29.05.2007 10:39:01 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
29.05.2007 10:39:02 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
29.05.2007 10:39:02 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
29.05.2007 10:39:02 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : at/pcd/wam/technologie/model/AdvancedAddressModel.hbm.xml
29.05.2007 10:39:02 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: at.pcd.wam.technologie.model.AdvancedAddressModel -> I_80050_SAVE
29.05.2007 10:39:02 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
29.05.2007 10:39:02 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
29.05.2007 10:39:02 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
29.05.2007 10:39:02 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://mag2;databaseName=spc
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sa, password=****}
29.05.2007 10:39:02 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:sqlserver://mag2;databaseName=spc
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://mag2;databaseName=spc
29.05.2007 10:39:02 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sa, password=****}
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Microsoft SQL Server, version: 8.00.194
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Microsoft SQL Server 2005 JDBC Driver, version: 1.1.1501.101
29.05.2007 10:39:02 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
29.05.2007 10:39:02 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
29.05.2007 10:39:02 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
29.05.2007 10:39:02 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
29.05.2007 10:39:02 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
29.05.2007 10:39:02 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
29.05.2007 10:39:03 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: spc.dbo.I_80050_SAVE
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [plz, strasse, cc, geo_long, geo_lat, id]
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [pk__i_80050_save__55fbe981]
29.05.2007 10:39:03 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Hibernate: insert into spc.dbo.I_80050_SAVE (CC, GEO_LAT, GEO_LONG, STRASSE, PLZ, ID) values (?, ?, ?, ?, ?, ?)
29.05.2007 10:39:03 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: null
29.05.2007 10:39:03 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Wert für Parameternummer "6" 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 at.pcd.wam.technologie.test.TestFromTutorial.main(TestFromTutorial.java:32)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Wert für Parameternummer "6" 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)
... 16 more

Wie gesagt, ich denke dass einfach noch columns im Model fehlen (bin gerade dabei zu ergänzen - dachte halt es ginge auch so :( ).

mfg
 
Also entweder habe ich es überlesen oder du hast es nicht gesagt. Es wäre nämlich wichtig gewesen, wenn du erwähnt hättest, dass deine Tabellenstruktur anders aussieht als dein Model. Der Vorteil ist, wenn deine Tabellen von hibernate angelegt werden, dass sie direkt richtig angelegt werden, bzw geändert werden, wenn du was an deinem Model änderst, ohne dass du dich drum kümmern brauchst.

MFG

zEriX
 
Die Tabelle existiert ja schon! Sprich die soll nicht von Hibernate generiert werden sondern bestehende Einträge ergänzen/ändern. Mittlerweile habe ich es auch schon geschafft ein Insert auf eine eigens angelegte Dummy-Tabelle durchzuführen. Nun teste ich es wie oben beschrieben an jener Tabelle die Schwierigkeiten macht.

Vorweg (als ich den Thread aufmachte) wollte ich wissen ob eine Tabelle angelegt wird falls sie nicht existiert - wurde beantwortet und danach wollte ich eben wissen wie ich auf eine bestehende schreibend zugreifen kann.

Also muss die komplette Tabelle abgebildet sein - ich meld mich dann ob es funktioniert hat.

mfg

**EDIT**
funktioniert leider nach wie vor nicht..

Mein Model welches alle Tabellen Spalten abdeckt:
Code:
package at.pcd.bitte;

import java.util.Date;

public class MyAddressModel {

	private int id;

	private String guid;

	private String titel;

	private String vorname;

	private String zuname;

	private String email;

	private String telefon;

	private Integer ear;

	private Integer spam;

	private Integer gueltig;

	private String funktion;

	private String beschreibung;

	private String web;

	private Integer rid1;

	private Integer rid2;

	private Integer rid3;

	private Integer rid4;

	private String NRekey01;

	private Integer nrid5;

	private Date erstellt;

	private String geschlecht;

	private Date geburtsdatum;

	private String organisation;

	private Integer review;

	private String ort;

	private Integer anforderung;

	private Integer htmlmail;

	private Short nichtDeutsch;

	private String cc;

	private String plz;

	private String strasse;

	private Integer geoX;

	private Integer geoY;

	private String skype;

	private Double geoLat;

	private Double geoLong;

	private String mobiltel;

	private Integer geo;

	private String bahnhof;

	private Date aenderung;

	public MyAddressModel() {
		super();
	}

	public MyAddressModel(int id, String guid, String titel, String vorname, String zuname, String email, String telefon, Integer ear, Integer spam, Integer gueltig, String funktion, String beschreibung, String web, Integer rid1, Integer rid2, Integer rid3, Integer rid4, String rekey01, Integer nrid5, Date erstellt, String geschlecht, Date geburtsdatum, String organisation, Integer review, String ort, Integer anforderung, Integer htmlmail, Short nichtDeutsch, String cc, String plz, String strasse, Integer geoX, Integer geoY, String skype, Double geoLat, Double geoLong, String mobiltel, Integer geo, String bahnhof, Date aenderung) {
		super();
		this.id = id;
		this.guid = guid;
		this.titel = titel;
		this.vorname = vorname;
		this.zuname = zuname;
		this.email = email;
		this.telefon = telefon;
		this.ear = ear;
		this.spam = spam;
		this.gueltig = gueltig;
		this.funktion = funktion;
		this.beschreibung = beschreibung;
		this.web = web;
		this.rid1 = rid1;
		this.rid2 = rid2;
		this.rid3 = rid3;
		this.rid4 = rid4;
		NRekey01 = rekey01;
		this.nrid5 = nrid5;
		this.erstellt = erstellt;
		this.geschlecht = geschlecht;
		this.geburtsdatum = geburtsdatum;
		this.organisation = organisation;
		this.review = review;
		this.ort = ort;
		this.anforderung = anforderung;
		this.htmlmail = htmlmail;
		this.nichtDeutsch = nichtDeutsch;
		this.cc = cc;
		this.plz = plz;
		this.strasse = strasse;
		this.geoX = geoX;
		this.geoY = geoY;
		this.skype = skype;
		this.geoLat = geoLat;
		this.geoLong = geoLong;
		this.mobiltel = mobiltel;
		this.geo = geo;
		this.bahnhof = bahnhof;
		this.aenderung = aenderung;
	}

	public Date getAenderung() {
		return aenderung;
	}

	public void setAenderung(Date aenderung) {
		this.aenderung = aenderung;
	}

	public Integer getAnforderung() {
		return anforderung;
	}

	public void setAnforderung(Integer anforderung) {
		this.anforderung = anforderung;
	}

	public String getBahnhof() {
		return bahnhof;
	}

	public void setBahnhof(String bahnhof) {
		this.bahnhof = bahnhof;
	}

	public String getBeschreibung() {
		return beschreibung;
	}

	public void setBeschreibung(String beschreibung) {
		this.beschreibung = beschreibung;
	}

	public String getCc() {
		return cc;
	}

	public void setCc(String cc) {
		this.cc = cc;
	}

	public Integer getEar() {
		return ear;
	}

	public void setEar(Integer ear) {
		this.ear = ear;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getErstellt() {
		return erstellt;
	}

	public void setErstellt(Date erstellt) {
		this.erstellt = erstellt;
	}

	public String getFunktion() {
		return funktion;
	}

	public void setFunktion(String funktion) {
		this.funktion = funktion;
	}

	public Date getGeburtsdatum() {
		return geburtsdatum;
	}

	public void setGeburtsdatum(Date geburtsdatum) {
		this.geburtsdatum = geburtsdatum;
	}

	public Integer getGeo() {
		return geo;
	}

	public void setGeo(Integer geo) {
		this.geo = geo;
	}

	public Double getGeoLat() {
		return geoLat;
	}

	public void setGeoLat(Double geoLat) {
		this.geoLat = geoLat;
	}

	public Double getGeoLong() {
		return geoLong;
	}

	public void setGeoLong(Double geoLong) {
		this.geoLong = geoLong;
	}

	public Integer getGeoX() {
		return geoX;
	}

	public void setGeoX(Integer geoX) {
		this.geoX = geoX;
	}

	public Integer getGeoY() {
		return geoY;
	}

	public void setGeoY(Integer geoY) {
		this.geoY = geoY;
	}

	public String getGeschlecht() {
		return geschlecht;
	}

	public void setGeschlecht(String geschlecht) {
		this.geschlecht = geschlecht;
	}

	public Integer getGueltig() {
		return gueltig;
	}

	public void setGueltig(Integer gueltig) {
		this.gueltig = gueltig;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public Integer getHtmlmail() {
		return htmlmail;
	}

	public void setHtmlmail(Integer htmlmail) {
		this.htmlmail = htmlmail;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getMobiltel() {
		return mobiltel;
	}

	public void setMobiltel(String mobiltel) {
		this.mobiltel = mobiltel;
	}

	public Short getNichtDeutsch() {
		return nichtDeutsch;
	}

	public void setNichtDeutsch(Short nichtDeutsch) {
		this.nichtDeutsch = nichtDeutsch;
	}

	public String getNRekey01() {
		return NRekey01;
	}

	public void setNRekey01(String rekey01) {
		NRekey01 = rekey01;
	}

	public Integer getNrid5() {
		return nrid5;
	}

	public void setNrid5(Integer nrid5) {
		this.nrid5 = nrid5;
	}

	public String getOrganisation() {
		return organisation;
	}

	public void setOrganisation(String organisation) {
		this.organisation = organisation;
	}

	public String getOrt() {
		return ort;
	}

	public void setOrt(String ort) {
		this.ort = ort;
	}

	public String getPlz() {
		return plz;
	}

	public void setPlz(String plz) {
		this.plz = plz;
	}

	public Integer getReview() {
		return review;
	}

	public void setReview(Integer review) {
		this.review = review;
	}

	public Integer getRid1() {
		return rid1;
	}

	public void setRid1(Integer rid1) {
		this.rid1 = rid1;
	}

	public Integer getRid2() {
		return rid2;
	}

	public void setRid2(Integer rid2) {
		this.rid2 = rid2;
	}

	public Integer getRid3() {
		return rid3;
	}

	public void setRid3(Integer rid3) {
		this.rid3 = rid3;
	}

	public Integer getRid4() {
		return rid4;
	}

	public void setRid4(Integer rid4) {
		this.rid4 = rid4;
	}

	public String getSkype() {
		return skype;
	}

	public void setSkype(String skype) {
		this.skype = skype;
	}

	public Integer getSpam() {
		return spam;
	}

	public void setSpam(Integer spam) {
		this.spam = spam;
	}

	public String getStrasse() {
		return strasse;
	}

	public void setStrasse(String strasse) {
		this.strasse = strasse;
	}

	public String getTelefon() {
		return telefon;
	}

	public void setTelefon(String telefon) {
		this.telefon = telefon;
	}

	public String getTitel() {
		return titel;
	}

	public void setTitel(String titel) {
		this.titel = titel;
	}

	public String getVorname() {
		return vorname;
	}

	public void setVorname(String vorname) {
		this.vorname = vorname;
	}

	public String getWeb() {
		return web;
	}

	public void setWeb(String web) {
		this.web = web;
	}

	public String getZuname() {
		return zuname;
	}

	public void setZuname(String zuname) {
		this.zuname = zuname;
	}	
}

die hbm dazu:
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.bitte">
  <class name="at.pcd.bitte.MyAddressModel" table="I_80050_SAVE" schema="dbo" catalog="spc">
  
  	<!-- primary key -->
  	<id name="id" type="integer" column="ID">
  	<generator class="identity"></generator>
  	</id>
  	
  	<property name="aenderung" type="date" column="AENDERUNG"></property>
  	<property name="anforderung" type="integer" column="ANFORDERUNG"></property>
  	<property name="bahnhof" type="string" column="BAHNHOF"></property>
  	<property name="beschreibung" type="string" column="BESCHREIBUNG"></property>
  	<property name="cc" type="string" column="CC"></property>
  	<property name="ear" type="integer" column="EAR"></property>
  	<property name="email" type="string" column="EMAIL"></property>
  	<property name="erstellt" type="date" column="ERSTELLT"></property>
  	<property name="funktion" type="string" column="FUNKTION"></property>
  	<property name="geburtsdatum" type="date" column="GEBURTSDATUM"></property>
  	<property name="geo" type="integer" column="GEO"></property>
  	<property name="geoLat" type="double" column="GEO_LAT"></property>
  	<property name="geoLong" type="double" column="GEO_LONG"></property>
  	<property name="geoX" type="integer" column="GEO_X"></property>
  	<property name="geoY" type="integer" column="GEO_Y"></property>
  	<property name="geschlecht" type="string" column="GESCHLECHT"></property>
  	<property name="gueltig" type="integer" column="GUELTIG"></property>
  	<property name="guid" type="string" column="GUID"></property>
  	<property name="htmlmail" type="integer" column="HTMLMAIL"></property>
  	<property name="mobiltel" type="string" column="MOBILTEL"></property>
  	<property name="nichtDeutsch" type="short" column="NICHTDEUTSCH"></property>
  	<property name="NRekey01" type="string" column="N_REKEY01"></property>
  	<property name="nrid5" type="integer" column="NRID5"></property>
  	<property name="organisation" type="string" column="ORGANISTAION"></property>
  	<property name="ort" type="string" column="ORT"></property>
  	<property name="plz" type="string" column="PLZ"></property>
  	<property name="review" type="integer" column="REVIEW"></property>
  	<property name="rid1" type="integer" column="RID1"></property>
  	<property name="rid2" type="integer" column="RID2"></property>
  	<property name="rid3" type="integer" column="RID3"></property>
  	<property name="rid4" type="integer" column="RID4"></property>
  	<property name="skype" type="string" column="SKYPE"></property>
  	<property name="spam" type="integer" column="SPAM"></property>
  	<property name="strasse" type="string" column="STRASSE"></property>
  	<property name="telefon" type="string" column="TELEFON"></property>
  	<property name="titel" type="string" column="TITEL"></property>
  	<property name="vorname" type="string" column="VORNAME"></property>
  	<property name="web" type="string" column="WEB"></property>
  	<property name="zuname" type="string" column="ZUNAME"></property>
  
  </class>
</hibernate-mapping>

hibernate config:
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>

	<property name="hibernate.show.sql">true</property>
	<property name="hibernate.hbm2ddl.auto">update</property>


	<mapping
		resource="at/pcd/wam/technologie/model/AdvancedAddressModel.hbm.xml" />
	<mapping resource="at/pcd/bitte/MyAddressModel.hbm.xml" />

</session-factory>
</hibernate-configuration>

Test:
Code:
package at.pcd.wam.technologie.test;

import org.hibernate.Session;
import org.hibernate.Transaction;

import at.pcd.bitte.MyAddressModel;
import at.pcd.wam.technologie.hibernate.utility.HibernateUtil;

public class TestHibernate {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Session session = HibernateUtil.getCurrentSession();
		Transaction tx = session.beginTransaction();
		
		MyAddressModel my = new MyAddressModel();
		my.setZuname("blubblubblub");
		session.save(my);
		
		/* funktioniert - aus db lesen */
//		ArrayList<AdvancedAddressModel> aModel = (ArrayList<AdvancedAddressModel>)
//			session.createQuery("select id, countryCode from AdvancedAddressModel").list();
		//***
		
		tx.commit();
	}
}

Fehlermeldung:
29.05.2007 11:02:20 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Wert für Parameternummer "40" wurde nicht festgelegt.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [at.pcd.bitte.MyAddressModel]
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:22)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Wert für Parameternummer "40" 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
 
Zuletzt bearbeitet:
Also wenn ich jetzt so drüber nachdenke, müsste es eigentlich egal sein wieviele Spalten deine Tabelle hat, solange sie nicht weniger hat.

Versuch es mal bitte mit dem automatischen anlegen der Tabelle.

MFG

zEriX
 
Ok, die Tabelle (eben anderen Namen) habe ich nun mittels Hibernate anlegen können, jedoch funktioniert ein Insert nicht, da die Tabelle keine Einträge besitzt (bekomme aber keine Exception).
 

Neue Beiträge

Zurück