Hello,
I'am using a db MS SQL Server 2005.
When I generateCreateSchemaScript and do a query.executeSQLQuery("...");
I have an error stack saying this error at top : could not execute native bulk manipulation query
In fact, it tries to add foreign key twice, so the db server "throw an exception".
Code:
private static void generateSQLDrop() {
Session session = hibernateSessionHelper.getSessionFactory()
.openSession();
Transaction tx = session.beginTransaction();
String[] sqls = cfg
.generateDropSchemaScript( lSessionFactoryImplementor
.getDialect() );
try
{
executeUpdate( sqls, session );
tx.commit();
}
catch (Exception e)
{
}
}
private static void executeUpdate(String[] pQueries, Session session)
throws Exception {
Statement st = ds.getConnection().createStatement();
for (String sql : pQueries)
{
try
{
Query q = session.createSQLQuery( sql );
q.executeUpdate();
}
catch (HibernateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
// throw e;
}
}
}
And the error when I launch script :
Quote:
Hibernate: create table msc_action (id numeric(19,0) identity not null, nom nvarchar(255) null unique, primary key (id))
org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:174)
at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1163)
at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:334)
at org.alfresco.module.msc_core.activite.config.GenerateSQL.executeUpdate(GenerateSQL.java:51)
at org.alfresco.module.msc_core.activite.config.GenerateSQL.generateSQLCreate(GenerateSQL.java:75)
at org.alfresco.module.msc_core.activite.config.GenerateSQL.main(GenerateSQL.java:157)
Caused by: java.sql.SQLException: Il existe déjà un objet nommé 'msc_action' dans la base de données.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:165)
... 5 more
Hibernate: create table msc_courrier (id numeric(19,0) not null, natPiece nvarchar(255) null, natContrat nvarchar(255) null, declaration tinyint null, etat numeric(19,0) not null, detenteur numeric(19,0) not null, personne_id numeric(19,0) null, etat_id numeric(19,0) null, primary key (id))
org.hibernate.exception.SQLGrammarException: could not execute native bulk manipulation query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:174)
at org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1163)
at org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:334)
at org.alfresco.module.msc_core.activite.config.GenerateSQL.executeUpdate(GenerateSQL.java:51)
at org.alfresco.module.msc_core.activite.config.GenerateSQL.generateSQLCreate(GenerateSQL.java:75)
at org.alfresco.module.msc_core.activite.config.GenerateSQL.main(GenerateSQL.java:157)
Caused by: java.sql.SQLException: Il existe déjà un objet nommé 'msc_courrier' dans la base de données.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:165)
... 5 more
PS : when I print the sql code generated, It is very good and a copy paste in SQL client do the creation a the tables...why hibernate do not "simply" do the same (execute the statement once) ?
Thanks for your help