-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Daten aus Transaktion direkt nutzen
PostPosted: Sat Jan 26, 2008 7:33 am 
Newbie

Joined: Sat Jan 26, 2008 7:19 am
Posts: 11
Location: Germany, Huerth
Hibernate version:
3.2

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package de.flabben.application;

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

import de.flabben.hibernate.InitSessionFactory;
import de.flabben.table.*;

/**
*
* @author jpieper
*/
public class Main
{
    /**
     * @access public
     * @param  String[] argv
     * @return void
     */
    public static void main(String[] argv)
    {
        Transaction tx = null;
        Session session = InitSessionFactory.getInstance().getCurrentSession();
       
        try
        {
            tx = session.beginTransaction();
           
            Author author = new Author();
            author.setName("Jan Pieper");
            author.setLogin("jpieper");
            author.setPassword("test1234");
            author.setEmail("j.pieper@example.com");
            session.save(author);
           
            Category category = new Category();
            category.setName("Testing");
            session.save(category);
           
            Tag tag = new Tag();
            tag.setName("Test");
            session.save(tag);
           
            java.util.Date date = new java.util.Date();
            java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime());
           
            Article article = new Article();
            article.setTitle("Testartikel");
            article.setContent("Dies ist ein kleiner, aber feiner Testartikel");
            article.setDate(timestamp);
            article.setCategoryId(1);
            article.setAuthorId(1);
            session.save(article);
           
            Comment comment = new Comment();
            comment.setTitle("Dies ist ein Testkommentar");
            comment.setContent("Ist ja super, wie Hibernate funktioniert.");
            comment.setDate(timestamp);
            comment.setAuthorId(1);
            comment.setArticleId(1);
            session.save(comment);
           
            tx.commit();
            session.close();
        }
        catch (HibernateException e)
        {
            e.printStackTrace();
            if ((tx != null) && tx.isActive()) {
                tx.rollback();
            }
        }
    }
}


Full stack trace of any exception that occurs:
Code:
init:
deps-jar:
Compiling 1 source file to /home/jpieper/NetBeansProjects/FlabbenHibernate/build/classes
compile:
run:
12:24:14,483  INFO Environment:514 - Hibernate 3.2.5
12:24:14,523  INFO Environment:532 - loaded properties from resource hibernate.properties: {<hibernate-configuration>=, <session-factory>=, <mapping=resource="de/flabben/table/definition/tag.hbm.xml" />, "-//Hibernate/Hibernate=Configuration DTD 3.0//EN", </session-factory>=, <?xml=version="1.0" encoding="utf-8"?>, hibernate.bytecode.use_reflection_optimizer=false, </hibernate-configuration>=, <!--=mapping files -->, "http=//hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">, <!DOCTYPE=hibernate-configuration PUBLIC, <property=name="hibernate.show_sql">true</property>}
12:24:14,528  INFO Environment:681 - Bytecode provider name : cglib
12:24:14,539  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
12:24:14,628  INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
12:24:14,643  INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
12:24:15,021  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/article.hbm.xml
12:24:15,196  INFO HbmBinder:300 - Mapping class: de.flabben.table.Article -> article
12:24:15,219  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/author.hbm.xml
12:24:15,287  INFO HbmBinder:300 - Mapping class: de.flabben.table.Author -> author
12:24:15,290  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/category.hbm.xml
12:24:15,339  INFO HbmBinder:300 - Mapping class: de.flabben.table.Category -> category
12:24:15,342  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/comment.hbm.xml
12:24:15,422  INFO HbmBinder:300 - Mapping class: de.flabben.table.Comment -> comment
12:24:15,425  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/tag.hbm.xml
12:24:15,460  INFO HbmBinder:300 - Mapping class: de.flabben.table.Tag -> tag
12:24:15,462  INFO Configuration:1541 - Configured SessionFactory: null
12:24:15,464 DEBUG InitSessionFactory:118 - classic factory
12:24:15,706  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
12:24:15,708  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
12:24:15,709  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
12:24:15,754  INFO DriverManagerConnectionProvider:80 - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/flabben
12:24:15,755  INFO DriverManagerConnectionProvider:86 - connection properties: {user=jpieper, password=****}
12:24:15,850  WARN SettingsFactory:117 - Could not obtain connection metadata
org.postgresql.util.PSQLException: Verbindung verweigert. Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass der Datenbankserver TCP/IP-Verbindungen annimmt.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:122)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
        at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
        at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
        at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
        at org.postgresql.Driver.makeConnection(Driver.java:382)
        at org.postgresql.Driver.connect(Driver.java:260)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:154)
        at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
        at de.flabben.hibernate.InitSessionFactory.initSessionFactory(InitSessionFactory.java:119)
        at de.flabben.hibernate.InitSessionFactory.getInstance(InitSessionFactory.java:60)
        at de.flabben.application.Main.main(Main.java:29)
Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)
        at java.net.Socket.<init>(Socket.java:366)
        at java.net.Socket.<init>(Socket.java:180)
        at org.postgresql.core.PGStream.<init>(PGStream.java:59)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:77)
        ... 15 more
12:24:15,958  INFO Dialect:152 - Using dialect: org.hibernate.dialect.PostgreSQLDialect
12:24:15,970  INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
12:24:15,976  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:24:15,977  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
12:24:15,977  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
12:24:15,981  INFO SettingsFactory:162 - Scrollable result sets: disabled
12:24:15,981  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
12:24:15,981  INFO SettingsFactory:178 - Connection release mode: auto
12:24:15,982  INFO SettingsFactory:205 - Default batch fetch size: 1
12:24:15,982  INFO SettingsFactory:209 - Generate SQL with comments: disabled
12:24:15,982  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
12:24:15,982  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
12:24:15,983  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:24:15,985  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
12:24:15,985  INFO SettingsFactory:225 - Query language substitutions: {}
12:24:15,987  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
12:24:15,987  INFO SettingsFactory:235 - Second-level cache: enabled
12:24:15,987  INFO SettingsFactory:239 - Query cache: disabled
12:24:15,988  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
12:24:15,988  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
12:24:15,988  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
12:24:15,996  INFO SettingsFactory:283 - Echoing all SQL to stdout
12:24:15,996  INFO SettingsFactory:290 - Statistics: disabled
12:24:15,996  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
12:24:15,996  INFO SettingsFactory:309 - Default entity-mode: pojo
12:24:15,997  INFO SettingsFactory:313 - Named query checking : enabled
12:24:16,228  INFO SessionFactoryImpl:161 - building session factory
12:24:16,757  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
12:24:16,863  WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 08004
12:24:16,864 ERROR JDBCExceptionReporter:78 - Verbindung verweigert. Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass der Datenbankserver TCP/IP-Verbindungen annimmt.
org.hibernate.exception.JDBCConnectionException: Cannot open connection
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
        at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
        at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
        at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
        at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
        at $Proxy0.beginTransaction(Unknown Source)
        at de.flabben.application.Main.main(Main.java:33)
Caused by: org.postgresql.util.PSQLException: Verbindung verweigert. Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass der Datenbankserver TCP/IP-Verbindungen annimmt.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:122)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
        at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
        at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
        at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
        at org.postgresql.Driver.makeConnection(Driver.java:382)
        at org.postgresql.Driver.connect(Driver.java:260)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:154)
        at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
        ... 11 more
Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)
        at java.net.Socket.<init>(Socket.java:366)
        at java.net.Socket.<init>(Socket.java:180)
        at org.postgresql.core.PGStream.<init>(PGStream.java:59)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:77)
        ... 21 more
BUILD SUCCESSFUL (total time: 4 seconds)


Name and version of the database you are using:
PostgreSQL 8.2

Problem:
Wenn ihr euch meinen Code anschaut, seht ihr sicherlich direkt, was ich falsch mache, aber für mich ist das etwas neu. Problem ist einfach, dass ich den Code so nicht ausführen kann. Scheinbat funktionieren die Transaktionen nicht so, wie ich sie kenne. Ich trage eine Kategorie ein und möchte diese auch direkt dem Artikel zuweisen, aber scheinbar ist die Kategorie zu dem Zeitpunkt für diese Transaktion noch nicht verfügbar, da die Kategorie erst nach dem comit() der Transaktion vorhanden ist.

Wenn ich nun um jedes save() eine Transaktion mache, habe ich ja nicht wirklich eine Transaktion und riskiere indirekt Inkonsistenzen.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 7:39 am 
Regular
Regular

Joined: Thu Jun 08, 2006 5:32 pm
Posts: 52
Das Problem liegt glaube ich eher dadran:

org.postgresql.util.PSQLException: Verbindung verweigert. Überprüfen Sie die Korrektheit von Hostnamen und der Portnummer und dass der Datenbankserver TCP/IP-Verbindungen annimmt.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 8:01 am 
Newbie

Joined: Sat Jan 26, 2008 7:19 am
Posts: 11
Location: Germany, Huerth
Oh, mein Fehler. Habe vergessen die Datenbank zu starten. Hier nun mal das Stacktrace, welches ich eigentlich meinte:

Code:
init:
deps-jar:
compile:
run:
12:55:07,172  INFO Environment:514 - Hibernate 3.2.5
12:55:07,182  INFO Environment:532 - loaded properties from resource hibernate.properties: {<hibernate-configuration>=, <session-factory>=, <mapping=resource="de/flabben/table/definition/tag.hbm.xml" />, "-//Hibernate/Hibernate=Configuration DTD 3.0//EN", </session-factory>=, <?xml=version="1.0" encoding="utf-8"?>, hibernate.bytecode.use_reflection_optimizer=false, </hibernate-configuration>=, <!--=mapping files -->, "http=//hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">, <!DOCTYPE=hibernate-configuration PUBLIC, <property=name="hibernate.show_sql">true</property>}
12:55:07,187  INFO Environment:681 - Bytecode provider name : cglib
12:55:07,191  INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
12:55:07,244  INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
12:55:07,245  INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
12:55:07,487  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/article.hbm.xml
12:55:07,592  INFO HbmBinder:300 - Mapping class: de.flabben.table.Article -> article
12:55:07,622  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/author.hbm.xml
12:55:07,660  INFO HbmBinder:300 - Mapping class: de.flabben.table.Author -> author
12:55:07,662  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/category.hbm.xml
12:55:07,696  INFO HbmBinder:300 - Mapping class: de.flabben.table.Category -> category
12:55:07,698  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/comment.hbm.xml
12:55:07,715  INFO HbmBinder:300 - Mapping class: de.flabben.table.Comment -> comment
12:55:07,716  INFO Configuration:553 - Reading mappings from resource : de/flabben/table/definition/tag.hbm.xml
12:55:07,730  INFO HbmBinder:300 - Mapping class: de.flabben.table.Tag -> tag
12:55:07,750  INFO Configuration:1541 - Configured SessionFactory: null
12:55:07,751 DEBUG InitSessionFactory:118 - classic factory
12:55:07,823  INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
12:55:07,824  INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
12:55:07,824  INFO DriverManagerConnectionProvider:45 - autocommit mode: false
12:55:07,842  INFO DriverManagerConnectionProvider:80 - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/flabben
12:55:07,843  INFO DriverManagerConnectionProvider:86 - connection properties: {user=jpieper, password=****}
12:55:07,910  INFO SettingsFactory:89 - RDBMS: PostgreSQL, version: 8.2.6
12:55:07,912  INFO SettingsFactory:90 - JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.2 JDBC3 with SSL (build 506)
12:55:07,930  INFO Dialect:152 - Using dialect: org.hibernate.dialect.PostgreSQLDialect
12:55:07,938  INFO TransactionFactoryFactory:34 - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
12:55:07,943  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
12:55:07,944  INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
12:55:07,944  INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
12:55:07,945  INFO SettingsFactory:154 - JDBC batch size: 15
12:55:07,946  INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled
12:55:07,947  INFO SettingsFactory:162 - Scrollable result sets: enabled
12:55:07,947  INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): disabled
12:55:07,948  INFO SettingsFactory:178 - Connection release mode: auto
12:55:07,949  INFO SettingsFactory:205 - Default batch fetch size: 1
12:55:07,950  INFO SettingsFactory:209 - Generate SQL with comments: disabled
12:55:07,951  INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
12:55:07,952  INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
12:55:07,952  INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
12:55:07,955  INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
12:55:07,955  INFO SettingsFactory:225 - Query language substitutions: {}
12:55:07,956  INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
12:55:07,957  INFO SettingsFactory:235 - Second-level cache: enabled
12:55:07,957  INFO SettingsFactory:239 - Query cache: disabled
12:55:07,958  INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
12:55:07,959  INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
12:55:07,959  INFO SettingsFactory:263 - Structured second-level cache entries: disabled
12:55:07,963  INFO SettingsFactory:283 - Echoing all SQL to stdout
12:55:07,964  INFO SettingsFactory:290 - Statistics: disabled
12:55:07,965  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
12:55:07,966  INFO SettingsFactory:309 - Default entity-mode: pojo
12:55:07,969  INFO SettingsFactory:313 - Named query checking : enabled
12:55:08,006  INFO SessionFactoryImpl:161 - building session factory
12:55:08,313  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
12:55:08,410 DEBUG SQL:401 - select nextval ('flabben.author_author_id_seq')
Hibernate: select nextval ('flabben.author_author_id_seq')
12:55:08,452 DEBUG SQL:401 - select nextval ('flabben.category_category_id_seq')
Hibernate: select nextval ('flabben.category_category_id_seq')
12:55:08,454 DEBUG SQL:401 - select nextval ('flabben.tag_tag_id_seq')
Hibernate: select nextval ('flabben.tag_tag_id_seq')
12:55:08,456 DEBUG SQL:401 - select nextval ('flabben.article_article_id_seq')
Hibernate: select nextval ('flabben.article_article_id_seq')
12:55:08,458 DEBUG SQL:401 - select nextval ('flabben.comment_comment_id_seq')
Hibernate: select nextval ('flabben.comment_comment_id_seq')
12:55:08,468 DEBUG SQL:401 - insert into flabben.author (author_name, author_login, author_password, author_email, author_id) values (?, ?, ?, ?, ?)
Hibernate: insert into flabben.author (author_name, author_login, author_password, author_email, author_id) values (?, ?, ?, ?, ?)
12:55:08,473 DEBUG SQL:401 - insert into flabben.category (category_name, category_id) values (?, ?)
Hibernate: insert into flabben.category (category_name, category_id) values (?, ?)
12:55:08,476 DEBUG SQL:401 - insert into flabben.tag (tag_name, tag_id) values (?, ?)
Hibernate: insert into flabben.tag (tag_name, tag_id) values (?, ?)
12:55:08,482 DEBUG SQL:401 - insert into flabben.article (article_title, article_content, article_date, category_id, author_id, article_id) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into flabben.article (article_title, article_content, article_date, category_id, author_id, article_id) values (?, ?, ?, ?, ?, ?)
12:55:08,613  WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: null
12:55:08,614 ERROR JDBCExceptionReporter:78 - Batch-Eintrag 0 insert into flabben.article (article_title, article_content, article_date, category_id, author_id, article_id) values (Testartikel, Dies ist ein kleiner, aber feiner Testartikel, 2008-01-26 12:55:08.455000 +01:00:00, 1, 1, 5) wurde abgebrochen.  Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
12:55:08,616  WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: 23503
12:55:08,619 ERROR JDBCExceptionReporter:78 - FEHLER: Einfügen oder Aktualisieren in Tabelle »article« verletzt Fremdschlüssel-Constraint »article_author_id_fkey«
  Detail: Schlüssel (author_id)=(1) ist nicht in Tabelle »author« vorhanden.
12:55:08,625 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
        at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
        at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at de.flabben.application.Main.main(Main.java:69)
Caused by: java.sql.BatchUpdateException: Batch-Eintrag 0 insert into flabben.article (article_title, article_content, article_date, category_id, author_id, article_id) values (Testartikel, Dies ist ein kleiner, aber feiner Testartikel, 2008-01-26 12:55:08.455000 +01:00:00, 1, 1, 5) wurde abgebrochen.  Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
        at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2534)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2596)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
        ... 15 more
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
        at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
        at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
        at de.flabben.application.Main.main(Main.java:69)
Caused by: java.sql.BatchUpdateException: Batch-Eintrag 0 insert into flabben.article (article_title, article_content, article_date, category_id, author_id, article_id) values (Testartikel, Dies ist ein kleiner, aber feiner Testartikel, 2008-01-26 12:55:08.455000 +01:00:00, 1, 1, 5) wurde abgebrochen.  Rufen Sie 'getNextException' auf, um die Ursache zu erfahren.
        at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2534)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1317)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:350)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2596)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
        ... 15 more
BUILD SUCCESSFUL (total time: 2 seconds)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 8:08 am 
Regular
Regular

Joined: Thu Jun 08, 2006 5:32 pm
Posts: 52
Steht doch alles da:

Schlüssel (author_id)=(1) ist nicht in Tabelle »author« vorhanden.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 8:24 am 
Newbie

Joined: Sat Jan 26, 2008 7:19 am
Posts: 11
Location: Germany, Huerth
Schau mal bitte in meinen Code, wie du siehst wird da ja eigentlich ein Author angelehgt, bevor ich den Artikel anlegen will. Das ist ja gerade mein Problem. Der Author ist zum Zeitpunkt des Anlegens des Artikels nicht vorhanden. Ich tippe einfach mal darauf, dass es daran liegt, dass die Transaktion noch nicht comitted ist, aber meiner Auffassung nach widerspricht das einer Transaktion.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 26, 2008 9:14 am 
Newbie

Joined: Sat Jan 26, 2008 7:19 am
Posts: 11
Location: Germany, Huerth
Ach ich habe den Fehler gefunden. Lag eigentlich nur daran, weil ich die IDs statisch angegeben habe und meine Sequencen bereits eine höhere ID hatten. Habe alle Tabellen geleert und die Sequencen zurückgesetzt. Darüber hinaus habe ich die statischen IDs durch die gernerierten IDs ersetzt.

Funktioniert nun ohne Probleme, danke :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.