Unerklärliche Hibernate Exception

12
  1. #1
    mavinatic


    Unerklärliche Hibernate Exception
    Hey ihr Winterschlafenden

    Ich bekomme eine für mich unerklärliche Exception:

    Java Code:
    1. 19:59:24,896 INFO Environment:456 - Hibernate 3.0rc1
    2. 19:59:24,912 INFO Environment:469 - hibernate.properties not found
    3. 19:59:24,912 INFO Environment:502 - using CGLIB reflection optimizer
    4. 19:59:24,912 INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
    5. 19:59:24,912 INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
    6. 19:59:24,912 INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
    7. 19:59:25,224 INFO Configuration:439 - Mapping resource: account.hbm.xml
    8. 19:59:25,412 INFO HbmBinder:256 - Mapping class: de.Webshop.AccountManager.DataObjects.Account -> accounts
    9. 19:59:25,443 INFO Configuration:1340 - Configured SessionFactory: null
    10. 19:59:25,443 INFO Configuration:844 - processing extends queue
    11. 19:59:25,443 INFO Configuration:848 - processing collection mappings
    12. 19:59:25,443 INFO Configuration:857 - processing association property references
    13. 19:59:25,443 INFO Configuration:884 - processing foreign key constraints
    14. 19:59:25,521 INFO Dialect:89 - Using dialect: org.hibernate.dialect.MySQLDialect
    15. 19:59:25,521 INFO SettingsFactory:87 - Maximum outer join fetch depth: 2
    16. 19:59:25,521 INFO SettingsFactory:90 - Default batch fetch size: 1
    17. 19:59:25,521 INFO SettingsFactory:94 - Generate SQL with comments: disabled
    18. 19:59:25,521 INFO SettingsFactory:98 - Order SQL updates by primary key: disabled
    19. 19:59:25,521 INFO SettingsFactory:273 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    20. 19:59:25,537 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
    21. 19:59:25,537 INFO SettingsFactory:106 - Query language substitutions: {}
    22. 19:59:25,537 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
    23. 19:59:25,537 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
    24. 19:59:25,537 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
    25. 19:59:25,552 INFO DriverManagerConnectionProvider:80 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/webshop
    26. 19:59:25,552 INFO DriverManagerConnectionProvider:86 - connection properties: {user=customers, password=****, autocommit=true}
    27. 19:59:25,802 INFO SettingsFactory:148 - JDBC batch size: 15
    28. 19:59:25,802 INFO SettingsFactory:151 - JDBC batch updates for versioned data: disabled
    29. 19:59:25,818 INFO SettingsFactory:156 - Scrollable result sets: enabled
    30. 19:59:25,818 INFO SettingsFactory:164 - JDBC3 getGeneratedKeys(): enabled
    31. 19:59:25,818 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
    32. 19:59:25,818 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    33. 19:59:25,818 INFO SettingsFactory:176 - Automatic flush during beforeCompletion(): disabled
    34. 19:59:25,818 INFO SettingsFactory:179 - Automatic session close at end of transaction: disabled
    35. 19:59:25,818 INFO SettingsFactory:260 - Cache provider: org.hibernate.cache.EhCacheProvider
    36. 19:59:25,833 INFO SettingsFactory:187 - Second-level cache: enabled
    37. 19:59:25,833 INFO SettingsFactory:192 - Optimize cache for minimal puts: disabled
    38. 19:59:25,833 INFO SettingsFactory:199 - Structured second-level cache entries: enabled
    39. 19:59:25,833 INFO SettingsFactory:203 - Query cache: disabled
    40. 19:59:25,833 INFO SettingsFactory:210 - Echoing all SQL to stdout
    41. 19:59:25,833 INFO SettingsFactory:214 - Statistics: disabled
    42. 19:59:25,833 INFO SettingsFactory:218 - Deleted entity synthetic identifier rollback: disabled
    43. 19:59:25,833 INFO SettingsFactory:232 - Default entity-mode: pojo
    44. 19:59:25,974 INFO SessionFactoryImpl:140 - building session factory
    45. 19:59:25,974 DEBUG CacheManager:191 - Creating new CacheManager with default config
    46. 19:59:25,974 DEBUG CacheManager:164 - Configuring ehcache from classpath.
    47. 19:59:25,974 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Dokumente%20und%20Einstellungen/Administrator/Desktop/Projekte/Hibernate%20Test/libs/ehcache-1.1.jar!/ehcache-failsafe.xml
    48. 19:59:25,990 DEBUG Configuration$DiskStore:185 - Disk Store Path: C:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\
    49. 19:59:26,240 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
    50. 19:59:26,240 INFO Dialect:89 - Using dialect: org.hibernate.dialect.MySQLDialect
    51. 19:59:26,240 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
    52. 19:59:26,240 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
    53. 19:59:26,240 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
    54. 19:59:26,255 INFO DriverManagerConnectionProvider:80 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/webshop
    55. 19:59:26,255 INFO DriverManagerConnectionProvider:86 - connection properties: {user=customers, password=****, autocommit=true}
    56. 19:59:26,255 INFO SchemaUpdate:105 - Running hbm2ddl schema update
    57. 19:59:26,255 INFO SchemaUpdate:117 - fetching database metadata
    58. 19:59:26,287 INFO SchemaUpdate:133 - updating schema
    59. 19:59:26,287 INFO Configuration:844 - processing extends queue
    60. 19:59:26,287 INFO Configuration:848 - processing collection mappings
    61. 19:59:26,287 INFO Configuration:857 - processing association property references
    62. 19:59:26,287 INFO Configuration:884 - processing foreign key constraints
    63. 19:59:26,333 INFO TableMetadata:38 - table found: webshop.accounts
    64. 19:59:26,333 INFO TableMetadata:39 - columns: [id, username, email, password]
    65. 19:59:26,333 INFO TableMetadata:40 - foreign keys: []
    66. 19:59:26,333 INFO TableMetadata:41 - indexes: [primary]
    67. 19:59:26,333 INFO SchemaUpdate:153 - schema update complete
    68. 19:59:26,333 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost:3306/webshop
    69. 19:59:26,333 INFO SessionFactoryImpl:366 - Checking 0 named queries
    70. 19:59:26,396 DEBUG SQL:292 - SELECT * FROM accounts
    71. Hibernate: SELECT * FROM accounts
    72. 19:59:26,412 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: S0022
    73. 19:59:26,412 ERROR JDBCExceptionReporter:58 - Column 'ID0_' not found.
    74. Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
    75. at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    76. at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    77. at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    78. at org.hibernate.loader.Loader.doList(Loader.java:1502)
    79. at org.hibernate.loader.Loader.list(Loader.java:1482)
    80. at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
    81. at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
    82. at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
    83. at de.Webshop.AccountManager.Hibernate.HConnection.getAllAccounts(HConnection.java:32)
    84. at de.Webshop.AccountManager.Startup.Main.main(Main.java:27)
    85. Caused by: java.sql.SQLException: Column 'ID0_' not found.
    86. at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2316)
    87. at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1287)
    88. at org.hibernate.type.IntegerType.get(IntegerType.java:26)
    89. at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
    90. at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
    91. at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:650)
    92. at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:277)
    93. at org.hibernate.loader.Loader.doQuery(Loader.java:384)
    94. at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
    95. at org.hibernate.loader.Loader.doList(Loader.java:1499)
    96. ... 6 more


    Das hier ist die Hibernate.cfg.xml

    Java Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <!DOCTYPE hibernate-configuration PUBLIC
    3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    4. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    5. <hibernate-configuration>
    6. <session-factory>
    7. <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
    8. <property name="hibernate.connection.password">customers</property>
    9. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/webshop</property>
    10. <property name="hibernate.connection.username">customers</property>
    11. <property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
    12. <property name="hibernate.connection.pool_size">10</property>
    13. <property name="show_sql">true</property>
    14. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    15. <property name="connection.autocommit">true</property>
    16. <property name="hibernate.hbm2ddl.auto">update</property>
    17. <mapping resource="account.hbm.xml"/>
    18. </session-factory>
    19. </hibernate-configuration>


    account.hbm.xml
    Java Code:
    1. <?xml version="1.0"?>
    2. <!DOCTYPE hibernate-mapping PUBLIC
    3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    4. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    5. <hibernate-mapping>
    6. <class name="de.Webshop.AccountManager.DataObjects.Account" table="accounts">
    7. <id name="id" type="integer" column="ID" >
    8. <generator class="assigned"/>
    9. </id>
    10.  
    11. <property name="username">
    12. <column name="USERNAME" />
    13. </property>
    14. <property name="password">
    15. <column name="PASSWORD"/>
    16. </property>
    17. <property name="email">
    18. <column name="EMAIL"/>
    19. </property>
    20. </class>
    21. </hibernate-mapping>


    MainClass:

    Java Code:
    1. package de.Webshop.AccountManager.Startup;
    2. import java.util.List;
    3.  
    4. import org.hibernate.Session;
    5.  
    6. import de.Webshop.AccountManager.DataObjects.Account;
    7. import de.Webshop.AccountManager.Hibernate.HConnection;
    8.  
    9.  
    10. public class Main {
    11.  
    12. /**
    13.   * @param args
    14.   */
    15. public static void main(String[] args) {
    16. // TODO Auto-generated method stub
    17. HConnection connection = new HConnection();
    18. Session session = connection.createConnection();
    19. // Account account = new Account();
    20. // account.setId(1000);
    21. // account.setEmail("test@test-mail.com");
    22. // account.setUsername("test");
    23. // account.setPassword("test");
    24. //
    25. // connection.saveAccount(session, account);
    26.  
    27. List<Account> list = connection.getAllAccounts(session);
    28. for(int i=0;i<list.size();i++) {
    29. System.out.println(list.get(i).getUsername());
    30. }
    31. }
    32.  
    33. }


    HConnection-Class
    Java Code:
    1. package de.Webshop.AccountManager.Hibernate;
    2.  
    3.  
    4. import java.util.List;
    5.  
    6. import org.hibernate.Session;
    7. import org.hibernate.SessionFactory;
    8. import org.hibernate.Transaction;
    9. import org.hibernate.cfg.Configuration;
    10.  
    11. import de.Webshop.AccountManager.DataObjects.Account;
    12.  
    13. public class HConnection {
    14. public Session createConnection() {
    15. SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    16. Session session = sessionFactory.openSession();
    17.  
    18. return session;
    19. }
    20.  
    21. public void saveAccount(Session session, Account object) {
    22. Transaction tx = session.beginTransaction();
    23. session.save(object);
    24. tx.commit();
    25. }
    26. public void closeConnection(Session session) {
    27. session.flush();
    28. session.close();
    29. }
    30. public List<Account> getAllAccounts(Session session) {
    31. Transaction tx = session.beginTransaction();
    32. List<Account> accounts = session.createSQLQuery("SELECT * FROM accounts").addEntity("Account", Account.class).list();
    33. return accounts;
    34. }
    35. }


    Und noch die JavaBean: ACCOUNT
    Java Code:
    1. package de.Webshop.AccountManager.DataObjects;
    2.  
    3. public class Account {
    4. private String username;
    5. private String password;
    6. private String email;
    7. private long id;
    8.  
    9. public String getUsername() {
    10. return username;
    11. }
    12. public void setUsername(String username) {
    13. this.username = username;
    14. }
    15. public String getPassword() {
    16. return password;
    17. }
    18. public void setPassword(String password) {
    19. this.password = password;
    20. }
    21. public String getEmail() {
    22. return email;
    23. }
    24. public void setEmail(String email) {
    25. this.email = email;
    26. }
    27. public long getId() {
    28. return id;
    29. }
    30. public void setId(long id) {
    31. this.id = id;
    32. }
    33. }


    Ich hab nun alle meine Klassen gepostet, wie ihr seht habe ich keine Column "ID_0" ich versteh nicht warum ich dann die Exception dafür bekomme, denn meine TABLE Column ID nennt sich "ID" wofür ist diese ID_0? ich verstehs nicht.

    Gruß George

  2. #2
    Marcinek

    Steht drin:

    Column 'ID0_' not found.


    Für mich wäre das nicht "unerklärlich"

    Ich schätze mal, dass das passiert, wenn man select * from macht.

    Dann möchte er eine ID, er bennt sie um in id0, haben.

  3. #3
    mavinatic


    achso Meinst du ich soll SELECT ID,EMAIL,USERNAME,PASSWORD FROM ACCOUNTS?

  4. #4
    Marcinek

    Probiere es aus.

    Und an der session gibt es 2 createQuery(). Das eine erzeugt SQL und das andere HQL.

    Du müsstest das HQL verwenden.

  5. #5
    KSG9|sebastian


    Zuerst verwende die Methode createQuery - die nimmt HQL statt SQL. Damit brauchst du auch kein addEntity mehr.

    Existiert die Tabelle schon? Sicher das "id" kein reserviertes Schlüsselwort der Datenbank ist. Solche Dinge hatte ich auch schon.

  6. #6
    mavinatic


    Hallo ihrs,
    ich bekomme nun eine weitere exception?! Zu dem habe ich meine Table von der mysql datenbank auf account umbenannt nicht das ihr euch wundert?!. Ich hab das doch alles in der hibernate.cfg.xml eingetragen :O?! Warum gehts nicht?

    Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: account is not mapped.

  7. #7
    MySelV


    Hi,

    Dann teile Hibernate auch mit, dass du die Tabelle umbenannt hast:

    Java Code:
    1.  
    2. @Table(name = "account")
    3. public class Account {
    4.  
    5. }


    Wobei das eigentlich der Standardname für die Tabelle wäre. Ich weiß nicht wie clever Hibernate.ddl bei "update" ist. Mach mal ein drop-create zum Test.

    Edit: Poste nochmal deine hibernate.cfg.xml und auch dein Query, wie es jetzt aussieht. Diese AST Fehler hatte ich auch schon oft, obwohl nur die Syntax der Query falsch war.

  8. #8
    mavinatic


    <?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">org.gjt.mm.mysql.Driver</property>
    <property name="hibernate.connection.password">customers</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/webshop</property>
    <property name="hibernate.connection.username">customers</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
    <property name="hibernate.connection.pool_size">10</property>
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="connection.autocommit">true</property>
    <mapping resource="account.hbm.xml"/>
    </session-factory>
    </hibernate-configuration>


    Meine neue Exception (=org.hibernate.hql.ast.QuerySyntaxError: account is not mapped. [SELECT acc.ID,acc.USERNAME,acc.PASSWORD,acc.EMAIL FROM account AS acc])

  9. #9
    MySelV


    Hi,

    der Fehler liegt bei

    "FROM account AS acc".

    Hibernate arbeitet immer mit den Objekten! Das heißt du musst bei allen Zugriffen auf Tabellen den Klassennamen verwenden. Ergo: Account und nicht account!


    Grüße

  10. #10
    mavinatic


    Gut das hat geklappt aber ich verzweifel solangsam denn ich hab die nächste exception ;O

    Java Code:
    1. Exception in thread "main" org.hibernate.QueryException: could not resolve property: ID of: de.Webshop.AccountManager.DataObjects.Account [SELECT acc.ID,acc.USERNAME,acc.PASSWORD,acc.EMAIL FROM de.Webshop.AccountManager.DataObjects.Account AS acc]

  11. #11
    MySelV


    Morgen,

    die Felder / Attribute werden auch über das Objekt angesprochen und müssen deshalb genauso wie im Objekt sein. Groß- Kleinschreibung ist bei Java doch schon immer wichtig...
    So sollte es gehen: acc.id, ...

    Grüße

  12. #12
    mavinatic


    Was würde ich Ohne DICH machen? Danke Vielmals für die Hilfe! aber wieder ne exception wo ich nicht weiterweiß wenn ich das alles bei google eingebe bekomme ich keine ergebnisse

    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to de.Webshop.AccountManager.DataObjects.Account
    at de.Webshop.AccountManager.Startup.Main.main(Main.java:29)

    Es kann nicht nach ACCOUNT gecastet werden Oo warum? und wo caste Ich? Wahrscheinlich von DB zu Object?!

  13. #13
    MySelV


    Hi,

    jemanden anderen fragen, würdest du ohne mich

    Kompletter Stacktrace wäre gut, aber spontan tippe ich auch die Methode getAllAccounts()

    Grüße

    Edit: Am besten du debugst die Methode mal. Und es wäre gut, wenn du die Transaktion auch wieder schließt, nachdem du die Accounts abgefragt hast.

  14. #14
    mavinatic


    Die Klasse HConnection

    Java Code:
    1. package de.Webshop.AccountManager.Hibernate;
    2.  
    3.  
    4. import java.util.List;
    5.  
    6. import org.hibernate.Session;
    7. import org.hibernate.SessionFactory;
    8. import org.hibernate.Transaction;
    9. import org.hibernate.cfg.Configuration;
    10.  
    11. import de.Webshop.AccountManager.DataObjects.Account;
    12.  
    13. public class HConnection {
    14. public Session createConnection() {
    15. SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    16. Session session = sessionFactory.openSession();
    17.  
    18. return session;
    19. }
    20.  
    21. public void saveAccount(Session session, Account object) {
    22. Transaction tx = session.beginTransaction();
    23. session.save(object);
    24. tx.commit();
    25. }
    26. public void closeConnection(Session session) {
    27. session.flush();
    28. session.close();
    29. }
    30. public List<Account> getAllAccounts(Session session) {
    31. Transaction tx = session.beginTransaction();
    32. List<Account> accounts = session.createQuery("SELECT acc.id,acc.username,acc.password,acc.email FROM Account AS acc").list();
    33. tx.commit();
    34. return accounts;
    35. }
    36. }


    Kompletter Stracktrace...
    Java Code:
    1. 11:21:38,828 INFO Environment:456 - Hibernate 3.0rc1
    2. 11:21:38,828 INFO Environment:469 - hibernate.properties not found
    3. 11:21:38,844 INFO Environment:502 - using CGLIB reflection optimizer
    4. 11:21:38,844 INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
    5. 11:21:38,844 INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
    6. 11:21:38,844 INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
    7. 11:21:39,125 INFO Configuration:439 - Mapping resource: account.hbm.xml
    8. 11:21:39,219 INFO HbmBinder:256 - Mapping class: de.Webshop.AccountManager.DataObjects.Account -> account
    9. 11:21:39,266 INFO Configuration:1340 - Configured SessionFactory: null
    10. 11:21:39,266 INFO Configuration:844 - processing extends queue
    11. 11:21:39,266 INFO Configuration:848 - processing collection mappings
    12. 11:21:39,266 INFO Configuration:857 - processing association property references
    13. 11:21:39,266 INFO Configuration:884 - processing foreign key constraints
    14. 11:21:39,391 INFO Dialect:89 - Using dialect: org.hibernate.dialect.MySQLDialect
    15. 11:21:39,407 INFO SettingsFactory:87 - Maximum outer join fetch depth: 2
    16. 11:21:39,407 INFO SettingsFactory:90 - Default batch fetch size: 1
    17. 11:21:39,407 INFO SettingsFactory:94 - Generate SQL with comments: disabled
    18. 11:21:39,407 INFO SettingsFactory:98 - Order SQL updates by primary key: disabled
    19. 11:21:39,407 INFO SettingsFactory:273 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    20. 11:21:39,485 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
    21. 11:21:39,500 INFO SettingsFactory:106 - Query language substitutions: {}
    22. 11:21:39,516 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
    23. 11:21:39,516 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
    24. 11:21:39,516 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
    25. 11:21:39,547 INFO DriverManagerConnectionProvider:80 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/webshop
    26. 11:21:39,547 INFO DriverManagerConnectionProvider:86 - connection properties: {user=customers, password=****, autocommit=true}
    27. 11:21:39,797 INFO SettingsFactory:148 - JDBC batch size: 15
    28. 11:21:39,797 INFO SettingsFactory:151 - JDBC batch updates for versioned data: disabled
    29. 11:21:39,797 INFO SettingsFactory:156 - Scrollable result sets: enabled
    30. 11:21:39,797 INFO SettingsFactory:164 - JDBC3 getGeneratedKeys(): enabled
    31. 11:21:39,797 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
    32. 11:21:39,828 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    33. 11:21:39,828 INFO SettingsFactory:176 - Automatic flush during beforeCompletion(): disabled
    34. 11:21:39,828 INFO SettingsFactory:179 - Automatic session close at end of transaction: disabled
    35. 11:21:39,828 INFO SettingsFactory:260 - Cache provider: org.hibernate.cache.EhCacheProvider
    36. 11:21:39,828 INFO SettingsFactory:187 - Second-level cache: enabled
    37. 11:21:39,828 INFO SettingsFactory:192 - Optimize cache for minimal puts: disabled
    38. 11:21:39,828 INFO SettingsFactory:199 - Structured second-level cache entries: enabled
    39. 11:21:39,828 INFO SettingsFactory:203 - Query cache: disabled
    40. 11:21:39,828 INFO SettingsFactory:210 - Echoing all SQL to stdout
    41. 11:21:39,828 INFO SettingsFactory:214 - Statistics: disabled
    42. 11:21:39,828 INFO SettingsFactory:218 - Deleted entity synthetic identifier rollback: disabled
    43. 11:21:39,828 INFO SettingsFactory:232 - Default entity-mode: pojo
    44. 11:21:40,063 INFO SessionFactoryImpl:140 - building session factory
    45. 11:21:40,078 DEBUG CacheManager:191 - Creating new CacheManager with default config
    46. 11:21:40,078 DEBUG CacheManager:164 - Configuring ehcache from classpath.
    47. 11:21:40,094 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Dokumente%20und%20Einstellungen/Administrator/Desktop/Projekte/Hibernate%20Test/libs/ehcache-1.1.jar!/ehcache-failsafe.xml
    48. 11:21:40,094 DEBUG Configuration$DiskStore:185 - Disk Store Path: C:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\
    49. 11:21:40,453 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
    50. 11:21:40,453 INFO SessionFactoryImpl:366 - Checking 0 named queries
    51. 11:21:40,610 DEBUG parser:83 - throwQueryException() : no errors
    52. 11:21:40,672 DEBUG parser:83 - throwQueryException() : no errors
    53. 11:21:40,688 DEBUG parser:83 - throwQueryException() : no errors
    54. 11:21:40,703 DEBUG SQL:292 - select account0_.ID as col_0_0_, account0_.USERNAME as col_1_0_, account0_.PASSWORD as col_2_0_, account0_.EMAIL as col_3_0_ from account account0_
    55. Hibernate: select account0_.ID as col_0_0_, account0_.USERNAME as col_1_0_, account0_.PASSWORD as col_2_0_, account0_.EMAIL as col_3_0_ from account account0_
    56. Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to de.Webshop.AccountManager.DataObjects.Account
    57. at de.Webshop.AccountManager.Startup.Main.main(Main.java:29)

  15. #15
    mvitz


    Wieso gibst du beim dem HSQL Query immer alle Felder an?

    Java Code:
    1. ...
    2. public List<Account> getAllAccounts(Session session) {
    3. Transaction tx = session.beginTransaction();
    4. List<Account> accounts = session.createQuery("FROM Account").list();
    5. tx.commit();
    6. return accounts;
    7. }
    8. ...

  16. #16
    mavinatic


    weil ich sonst noch ne andere exception bekomme!

    Wenn ich nur das object ausgeben lasse:

    Java Code:
    1. List<Account> list = connection.getAllAccounts(session);
    2. for(int i=0;i<list.size();i++) {
    3. System.out.println(list.get(i));
    4. }


    funktionierts, wenn ich ne GET methode zb.: getUsername() dranhänge bekomm ich die exception!

  17. #17
    mvitz


    Also bei mir funktioniert es. Habe jedoch testweise lediglich H2 und nicht MySQL als Datenbank genutzt. Ich habe zwei Vermutungen woran das liegen könnte.

    1) Deine Hibernate Version (3.0.RC1) ist leicht veraltet, die neueste ist zur Zeit 3.5.4-Final.
    2) Du nutzt anscheinend MySQL im MyISAM Modus (org.hibernate.dialect.MySQLMyISAMDialect) und MyISAM unterstützt keine Transaktionen. Versuch es doch einmal über den InnoDB Modus.

  18. #18
    mavinatic


    Hallo ihrs

    Ich habe alles ausprobiert aber funktionierte NICHTS. Naja ich dachte mir nun ich fange einmal neu an und habe ein ganz simples tutorial genommen, welches ich auf meiner MYSQL Datenbank laufen lasse,... aber auch hier bekomme ich fehler

    FirstExample.java
    Java Code:
    1. import org.hibernate.Session;
    2. import org.hibernate.SessionFactory;
    3. import org.hibernate.cfg.Configuration;
    4.  
    5.  
    6. /**
    7.  * @author Deepak Kumar
    8.  *
    9.  * <a href="http://www.roseindia.net" target="_blank">JSP Tutorials,EJB Tutorial,JDBC Tutorials,Free Java Servlets Tutorials, WAP Tutorials, Spring Framework Tutorials, J2EE Tutorials, BioInformatics Tutorials, Java Server Faces Tutorials, Jboss Tutorials, Hibernate Tutorials, XML and MySQL Tutorials</a>
    10.  * Hibernate example to inset data into Contact table
    11.  */
    12. public class FirstExample {
    13. public static void main(String[] args) {
    14. Session session = null;
    15.  
    16. try{
    17. SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    18. session = sessionFactory.openSession();
    19.  
    20. System.out.println("Inserting Record");
    21. Contact contact = new Contact();
    22. contact.setId(3);
    23. contact.setFirstName("Deepak");
    24. contact.setLastName("Kumar");
    25. contact.setEmail("deepak_38@yahoo.com");
    26. session.save(contact);
    27. System.out.println("Done");
    28. }catch(Exception e){
    29. System.out.println(e.getMessage());
    30. }finally{
    31. // session.flush();
    32. session.close();
    33. }
    34.  
    35. }
    36. }


    Contact.hbm.xml
    [XML]<?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>
    <class name="Contact" table="test"><!-- CLASSPATH -->
    <id name="id" type="integer" column="id" >
    <generator class="assigned"/>
    </id>

    <property name="firstName">
    <column name="firstname" />
    </property>
    <property name="lastName">
    <column name="lastname"/>
    </property>
    <property name="email">
    <column name="email"/>
    </property>
    </class>
    </hibernate-mapping>[/XML]

    [XML]<?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">org.gjt.mm.mysql.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/webshop</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">admin</property>
    <property name="hibernate.connection.pool_size">10</property>
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <mapping resource="contact.hbm.xml"/>
    </session-factory>
    </hibernate-configuration>
    [/XML]

    Was mach ich falsch ich hatte bisher Hibernate nur an Oracle und da gings eigentlich immer problemlos...Was mach ich falsch?

    Den fehler den ich bekomme ist keiner! aber es wird nichts eingetragen!

    Stacktrace:
    Java Code:
    1. 12:43:29,212 INFO Environment:560 - Hibernate 3.3.2.GA
    2. 12:43:29,212 INFO Environment:593 - hibernate.properties not found
    3. 12:43:29,228 INFO Environment:771 - Bytecode provider name : javassist
    4. 12:43:29,228 INFO Environment:652 - using JDK 1.4 java.sql.Timestamp handling
    5. 12:43:29,369 INFO Configuration:1474 - configuring from resource: /hibernate.cfg.xml
    6. 12:43:29,369 INFO Configuration:1451 - Configuration resource: /hibernate.cfg.xml
    7. 12:43:29,478 INFO Configuration:600 - Reading mappings from resource : contact.hbm.xml
    8. 12:43:29,603 INFO HbmBinder:322 - Mapping class: Contact -> test
    9. 12:43:29,619 INFO Configuration:1589 - Configured SessionFactory: null
    10. 12:43:29,697 INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
    11. 12:43:29,697 INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 10
    12. 12:43:29,697 INFO DriverManagerConnectionProvider:68 - autocommit mode: false
    13. 12:43:29,712 INFO DriverManagerConnectionProvider:103 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost/webshop
    14. 12:43:29,728 INFO DriverManagerConnectionProvider:109 - connection properties: {user=root, password=****}
    15. 12:43:29,978 INFO SettingsFactory:114 - RDBMS: MySQL, version: 5.1.50-community
    16. 12:43:29,978 INFO SettingsFactory:115 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.0.16-ga ( $Date: 2004/09/30 07:35:03 $, $Revision: 1.27.2.44 $ )
    17. 12:43:30,025 INFO Dialect:175 - Using dialect: org.hibernate.dialect.MySQLDialect
    18. 12:43:30,025 INFO TransactionFactoryFactory:59 - Using default transaction strategy (direct JDBC transactions)
    19. 12:43:30,040 INFO TransactionManagerLookupFactory:80 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    20. 12:43:30,040 INFO SettingsFactory:161 - Automatic flush during beforeCompletion(): disabled
    21. 12:43:30,040 INFO SettingsFactory:165 - Automatic session close at end of transaction: disabled
    22. 12:43:30,040 INFO SettingsFactory:172 - JDBC batch size: 15
    23. 12:43:30,040 INFO SettingsFactory:175 - JDBC batch updates for versioned data: disabled
    24. 12:43:30,040 INFO SettingsFactory:180 - Scrollable result sets: enabled
    25. 12:43:30,040 INFO SettingsFactory:188 - JDBC3 getGeneratedKeys(): enabled
    26. 12:43:30,040 INFO SettingsFactory:196 - Connection release mode: auto
    27. 12:43:30,040 INFO SettingsFactory:220 - Maximum outer join fetch depth: 2
    28. 12:43:30,040 INFO SettingsFactory:223 - Default batch fetch size: 1
    29. 12:43:30,040 INFO SettingsFactory:227 - Generate SQL with comments: disabled
    30. 12:43:30,040 INFO SettingsFactory:231 - Order SQL updates by primary key: disabled
    31. 12:43:30,040 INFO SettingsFactory:235 - Order SQL inserts for batching: disabled
    32. 12:43:30,040 INFO SettingsFactory:397 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    33. 12:43:30,056 INFO ASTQueryTranslatorFactory:47 - Using ASTQueryTranslatorFactory
    34. 12:43:30,056 INFO SettingsFactory:243 - Query language substitutions: {}
    35. 12:43:30,056 INFO SettingsFactory:248 - JPA-QL strict compliance: disabled
    36. 12:43:30,056 INFO SettingsFactory:253 - Second-level cache: enabled
    37. 12:43:30,056 INFO SettingsFactory:257 - Query cache: disabled
    38. 12:43:30,056 INFO SettingsFactory:382 - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
    39. 12:43:30,056 INFO SettingsFactory:267 - Optimize cache for minimal puts: disabled
    40. 12:43:30,056 INFO SettingsFactory:276 - Structured second-level cache entries: disabled
    41. 12:43:30,056 INFO SettingsFactory:296 - Echoing all SQL to stdout
    42. 12:43:30,056 INFO SettingsFactory:305 - Statistics: disabled
    43. 12:43:30,056 INFO SettingsFactory:309 - Deleted entity synthetic identifier rollback: disabled
    44. 12:43:30,056 INFO SettingsFactory:324 - Default entity-mode: pojo
    45. 12:43:30,056 INFO SettingsFactory:328 - Named query checking : enabled
    46. 12:43:30,150 INFO SessionFactoryImpl:193 - building session factory
    47. 12:43:30,462 INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured
    48. Inserting Record
    49. Done

  19. #19
    mvitz


    Keine Transaktion genutzt! Abgesehen davon nutzt man als JDBC Driver Class mittlereweile com.mysql.jdbc.Driver

  20. #20
    mavinatic


    oke funktioniert aber mal gucken ob das mit der LISTE klappt^^

12

Keine Antwort auf Deine Suche gefunden? Registriere Dich kostenlos und stelle Deine eigene Frage zu Java!

Jetzt kostenlos registrieren