Hey ihr Winterschlafenden
Ich bekomme eine für mich unerklärliche Exception:
Das hier ist die Hibernate.cfg.xml
account.hbm.xml
MainClass:
HConnection-Class
Und noch die JavaBean: ACCOUNT
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
Ich bekomme eine für mich unerklärliche Exception:
Java:
19:59:24,896 INFO Environment:456 - Hibernate 3.0rc1
19:59:24,912 INFO Environment:469 - hibernate.properties not found
19:59:24,912 INFO Environment:502 - using CGLIB reflection optimizer
19:59:24,912 INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
19:59:24,912 INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
19:59:24,912 INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
19:59:25,224 INFO Configuration:439 - Mapping resource: account.hbm.xml
19:59:25,412 INFO HbmBinder:256 - Mapping class: de.Webshop.AccountManager.DataObjects.Account -> accounts
19:59:25,443 INFO Configuration:1340 - Configured SessionFactory: null
19:59:25,443 INFO Configuration:844 - processing extends queue
19:59:25,443 INFO Configuration:848 - processing collection mappings
19:59:25,443 INFO Configuration:857 - processing association property references
19:59:25,443 INFO Configuration:884 - processing foreign key constraints
19:59:25,521 INFO Dialect:89 - Using dialect: org.hibernate.dialect.MySQLDialect
19:59:25,521 INFO SettingsFactory:87 - Maximum outer join fetch depth: 2
19:59:25,521 INFO SettingsFactory:90 - Default batch fetch size: 1
19:59:25,521 INFO SettingsFactory:94 - Generate SQL with comments: disabled
19:59:25,521 INFO SettingsFactory:98 - Order SQL updates by primary key: disabled
19:59:25,521 INFO SettingsFactory:273 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
19:59:25,537 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
19:59:25,537 INFO SettingsFactory:106 - Query language substitutions: {}
19:59:25,537 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
19:59:25,537 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
19:59:25,537 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
19:59:25,552 INFO DriverManagerConnectionProvider:80 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/webshop
19:59:25,552 INFO DriverManagerConnectionProvider:86 - connection properties: {user=customers, password=****, autocommit=true}
19:59:25,802 INFO SettingsFactory:148 - JDBC batch size: 15
19:59:25,802 INFO SettingsFactory:151 - JDBC batch updates for versioned data: disabled
19:59:25,818 INFO SettingsFactory:156 - Scrollable result sets: enabled
19:59:25,818 INFO SettingsFactory:164 - JDBC3 getGeneratedKeys(): enabled
19:59:25,818 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
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)
19:59:25,818 INFO SettingsFactory:176 - Automatic flush during beforeCompletion(): disabled
19:59:25,818 INFO SettingsFactory:179 - Automatic session close at end of transaction: disabled
19:59:25,818 INFO SettingsFactory:260 - Cache provider: org.hibernate.cache.EhCacheProvider
19:59:25,833 INFO SettingsFactory:187 - Second-level cache: enabled
19:59:25,833 INFO SettingsFactory:192 - Optimize cache for minimal puts: disabled
19:59:25,833 INFO SettingsFactory:199 - Structured second-level cache entries: enabled
19:59:25,833 INFO SettingsFactory:203 - Query cache: disabled
19:59:25,833 INFO SettingsFactory:210 - Echoing all SQL to stdout
19:59:25,833 INFO SettingsFactory:214 - Statistics: disabled
19:59:25,833 INFO SettingsFactory:218 - Deleted entity synthetic identifier rollback: disabled
19:59:25,833 INFO SettingsFactory:232 - Default entity-mode: pojo
19:59:25,974 INFO SessionFactoryImpl:140 - building session factory
19:59:25,974 DEBUG CacheManager:191 - Creating new CacheManager with default config
19:59:25,974 DEBUG CacheManager:164 - Configuring ehcache from classpath.
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
19:59:25,990 DEBUG Configuration$DiskStore:185 - Disk Store Path: C:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\
19:59:26,240 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
19:59:26,240 INFO Dialect:89 - Using dialect: org.hibernate.dialect.MySQLDialect
19:59:26,240 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
19:59:26,240 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 10
19:59:26,240 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
19:59:26,255 INFO DriverManagerConnectionProvider:80 - using driver: org.gjt.mm.mysql.Driver at URL: jdbc:mysql://localhost:3306/webshop
19:59:26,255 INFO DriverManagerConnectionProvider:86 - connection properties: {user=customers, password=****, autocommit=true}
19:59:26,255 INFO SchemaUpdate:105 - Running hbm2ddl schema update
19:59:26,255 INFO SchemaUpdate:117 - fetching database metadata
19:59:26,287 INFO SchemaUpdate:133 - updating schema
19:59:26,287 INFO Configuration:844 - processing extends queue
19:59:26,287 INFO Configuration:848 - processing collection mappings
19:59:26,287 INFO Configuration:857 - processing association property references
19:59:26,287 INFO Configuration:884 - processing foreign key constraints
19:59:26,333 INFO TableMetadata:38 - table found: webshop.accounts
19:59:26,333 INFO TableMetadata:39 - columns: [id, username, email, password]
19:59:26,333 INFO TableMetadata:40 - foreign keys: []
19:59:26,333 INFO TableMetadata:41 - indexes: [primary]
19:59:26,333 INFO SchemaUpdate:153 - schema update complete
19:59:26,333 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:mysql://localhost:3306/webshop
19:59:26,333 INFO SessionFactoryImpl:366 - Checking 0 named queries
19:59:26,396 DEBUG SQL:292 - SELECT * FROM accounts
Hibernate: SELECT * FROM accounts
19:59:26,412 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: S0022
19:59:26,412 ERROR JDBCExceptionReporter:58 - Column 'ID0_' not found.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1333)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:146)
at de.Webshop.AccountManager.Hibernate.HConnection.getAllAccounts(HConnection.java:32)
at de.Webshop.AccountManager.Startup.Main.main(Main.java:27)
Caused by: java.sql.SQLException: Column 'ID0_' not found.
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2316)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1287)
at org.hibernate.type.IntegerType.get(IntegerType.java:26)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:77)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:68)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:650)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:277)
at org.hibernate.loader.Loader.doQuery(Loader.java:384)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 6 more
Das hier ist die Hibernate.cfg.xml
Java:
<?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>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="account.hbm.xml"/>
</session-factory>
</hibernate-configuration>
account.hbm.xml
Java:
<?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="de.Webshop.AccountManager.DataObjects.Account" table="accounts">
<id name="id" type="integer" column="ID" >
<generator class="assigned"/>
</id>
<property name="username">
<column name="USERNAME" />
</property>
<property name="password">
<column name="PASSWORD"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>
MainClass:
Java:
package de.Webshop.AccountManager.Startup;
import java.util.List;
import org.hibernate.Session;
import de.Webshop.AccountManager.DataObjects.Account;
import de.Webshop.AccountManager.Hibernate.HConnection;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HConnection connection = new HConnection();
Session session = connection.createConnection();
// Account account = new Account();
// account.setId(1000);
// account.setEmail("test@test-mail.com");
// account.setUsername("test");
// account.setPassword("test");
//
// connection.saveAccount(session, account);
List<Account> list = connection.getAllAccounts(session);
for(int i=0;i<list.size();i++) {
System.out.println(list.get(i).getUsername());
}
}
}
HConnection-Class
Java:
package de.Webshop.AccountManager.Hibernate;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import de.Webshop.AccountManager.DataObjects.Account;
public class HConnection {
public Session createConnection() {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
return session;
}
public void saveAccount(Session session, Account object) {
Transaction tx = session.beginTransaction();
session.save(object);
tx.commit();
}
public void closeConnection(Session session) {
session.flush();
session.close();
}
public List<Account> getAllAccounts(Session session) {
Transaction tx = session.beginTransaction();
List<Account> accounts = session.createSQLQuery("SELECT * FROM accounts").addEntity("Account", Account.class).list();
return accounts;
}
}
Und noch die JavaBean: ACCOUNT
Java:
package de.Webshop.AccountManager.DataObjects;
public class Account {
private String username;
private String password;
private String email;
private long id;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
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