Шустрый

Профиль
Группа: Участник
Сообщений: 97
Регистрация: 2.8.2006
Репутация: нет Всего: нет
|
спасибо за пример, но что-то не получается, хотя с конфиг файлом для hsql БД все работало по аналогии сделала конфиг файл Код | <?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>
<!-- Database connection settings --> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306</property> <property name="connection.username">root</property> <property name="connection.password">123456</property>
<!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property>
<!-- SQL dialect --> <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout --> <property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">create</property>
<mapping resource="events/Event.hbm.xml"/> <mapping resource="events/Person.hbm.xml"/> <mapping resource="webShop/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
|
ругается вот так Код | начало программы 21:03:40,359 INFO Environment:514 - Hibernate 3.2.4.sp1 21:03:40,359 INFO Environment:547 - hibernate.properties not found 21:03:40,359 INFO Environment:681 - Bytecode provider name : cglib 21:03:40,375 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling 21:03:40,437 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml 21:03:40,437 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml 21:03:40,671 INFO Configuration:553 - Reading mappings from resource : events/Event.hbm.xml 21:03:40,765 INFO HbmBinder:300 - Mapping class: events.Event -> EVENTS 21:03:40,796 INFO HbmBinder:1422 - Mapping collection: events.Event.participants -> PERSON_EVENT 21:03:40,796 INFO Configuration:553 - Reading mappings from resource : events/Person.hbm.xml 21:03:40,828 INFO HbmBinder:300 - Mapping class: events.Person -> PERSON 21:03:40,828 INFO HbmBinder:1422 - Mapping collection: events.Person.events -> PERSON_EVENT 21:03:40,828 INFO HbmBinder:1422 - Mapping collection: events.Person.emailAddresses -> PERSON_EMAIL_ADDR 21:03:40,828 INFO Configuration:553 - Reading mappings from resource : webShop/User.hbm.xml 21:03:40,859 INFO HbmBinder:300 - Mapping class: webShop.User -> USER 21:03:40,859 INFO Configuration:1541 - Configured SessionFactory: null 21:03:40,937 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!) 21:03:40,937 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1 21:03:40,937 INFO DriverManagerConnectionProvider:45 - autocommit mode: false 21:03:40,937 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306 21:03:40,937 INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****} 21:03:41,171 INFO SettingsFactory:89 - RDBMS: MySQL, version: 5.0.41-community-nt 21:03:41,171 INFO SettingsFactory:90 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.6 ( $Date: 2007-03-09 22:13:57 +0100 (Fri, 09 Mar 2007) $, $Revision: 6341 $ ) 21:03:41,187 INFO Dialect:152 - Using dialect: org.hibernate.dialect.MySQLInnoDBDialect 21:03:41,187 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions) 21:03:41,187 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 21:03:41,187 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled 21:03:41,187 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled 21:03:41,187 INFO SettingsFactory:154 - JDBC batch size: 15 21:03:41,187 INFO SettingsFactory:157 - JDBC batch updates for versioned data: disabled 21:03:41,203 INFO SettingsFactory:162 - Scrollable result sets: enabled 21:03:41,203 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled 21:03:41,203 INFO SettingsFactory:178 - Connection release mode: auto 21:03:41,203 INFO SettingsFactory:202 - Maximum outer join fetch depth: 2 21:03:41,203 INFO SettingsFactory:205 - Default batch fetch size: 1 21:03:41,203 INFO SettingsFactory:209 - Generate SQL with comments: disabled 21:03:41,203 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled 21:03:41,203 INFO SettingsFactory:217 - Order SQL inserts for batching: disabled 21:03:41,203 INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 21:03:41,203 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory 21:03:41,203 INFO SettingsFactory:225 - Query language substitutions: {} 21:03:41,203 INFO SettingsFactory:230 - JPA-QL strict compliance: disabled 21:03:41,203 INFO SettingsFactory:235 - Second-level cache: enabled 21:03:41,203 INFO SettingsFactory:239 - Query cache: disabled 21:03:41,203 INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider 21:03:41,203 INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled 21:03:41,203 INFO SettingsFactory:263 - Structured second-level cache entries: disabled 21:03:41,203 INFO SettingsFactory:283 - Echoing all SQL to stdout 21:03:41,203 INFO SettingsFactory:290 - Statistics: disabled 21:03:41,203 INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled 21:03:41,203 INFO SettingsFactory:309 - Default entity-mode: pojo 21:03:41,203 INFO SettingsFactory:313 - Named query checking : enabled 21:03:41,234 INFO SessionFactoryImpl:161 - building session factory 21:03:41,546 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 21:03:41,546 INFO SchemaExport:154 - Running hbm2ddl schema export 21:03:41,546 DEBUG SchemaExport:170 - import file not found: /import.sql 21:03:41,546 INFO SchemaExport:179 - exporting generated schema to database 21:03:41,546 DEBUG SchemaExport:303 - alter table PERSON_EMAIL_ADDR drop foreign key FKA54215FE7708282F 21:03:41,562 DEBUG SchemaExport:288 - Unsuccessful: alter table PERSON_EMAIL_ADDR drop foreign key FKA54215FE7708282F 21:03:41,562 DEBUG SchemaExport:289 - No database selected 21:03:41,562 DEBUG SchemaExport:303 - alter table PERSON_EVENT drop foreign key FKAD91D910F96D1A45 21:03:41,562 DEBUG SchemaExport:288 - Unsuccessful: alter table PERSON_EVENT drop foreign key FKAD91D910F96D1A45 21:03:41,562 DEBUG SchemaExport:289 - No database selected 21:03:41,562 DEBUG SchemaExport:303 - alter table PERSON_EVENT drop foreign key FKAD91D9107708282F 21:03:41,562 DEBUG SchemaExport:288 - Unsuccessful: alter table PERSON_EVENT drop foreign key FKAD91D9107708282F 21:03:41,562 DEBUG SchemaExport:289 - No database selected 21:03:41,562 DEBUG SchemaExport:303 - drop table if exists EVENTS 21:03:41,562 DEBUG SchemaExport:288 - Unsuccessful: drop table if exists EVENTS 21:03:41,578 DEBUG SchemaExport:289 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - drop table if exists PERSON 21:03:41,578 DEBUG SchemaExport:288 - Unsuccessful: drop table if exists PERSON 21:03:41,578 DEBUG SchemaExport:289 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - drop table if exists PERSON_EMAIL_ADDR 21:03:41,578 DEBUG SchemaExport:288 - Unsuccessful: drop table if exists PERSON_EMAIL_ADDR 21:03:41,578 DEBUG SchemaExport:289 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - drop table if exists PERSON_EVENT 21:03:41,578 DEBUG SchemaExport:288 - Unsuccessful: drop table if exists PERSON_EVENT 21:03:41,578 DEBUG SchemaExport:289 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - drop table if exists USER 21:03:41,578 DEBUG SchemaExport:288 - Unsuccessful: drop table if exists USER 21:03:41,578 DEBUG SchemaExport:289 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - create table EVENTS (EVENT_ID bigint not null auto_increment, EVENT_DATE datetime, title varchar(255), primary key (EVENT_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: create table EVENTS (EVENT_ID bigint not null auto_increment, EVENT_DATE datetime, title varchar(255), primary key (EVENT_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - create table PERSON (PERSON_ID bigint not null auto_increment, age integer, firstname varchar(255), lastname varchar(255), primary key (PERSON_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: create table PERSON (PERSON_ID bigint not null auto_increment, age integer, firstname varchar(255), lastname varchar(255), primary key (PERSON_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - create table PERSON_EMAIL_ADDR (PERSON_ID bigint not null, EMAIL_ADDR varchar(255)) type=InnoDB 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: create table PERSON_EMAIL_ADDR (PERSON_ID bigint not null, EMAIL_ADDR varchar(255)) type=InnoDB 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - create table PERSON_EVENT (EVENT_ID bigint not null, PERSON_ID bigint not null, primary key (PERSON_ID, EVENT_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: create table PERSON_EVENT (EVENT_ID bigint not null, PERSON_ID bigint not null, primary key (PERSON_ID, EVENT_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - create table USER (USER_ID bigint not null auto_increment, firstname varchar(255), lastname varchar(255), email varchar(255), password varchar(255), login varchar(255), EVENT_DATE datetime, primary key (USER_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: create table USER (USER_ID bigint not null auto_increment, firstname varchar(255), lastname varchar(255), email varchar(255), password varchar(255), login varchar(255), EVENT_DATE datetime, primary key (USER_ID)) type=InnoDB 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - alter table PERSON_EMAIL_ADDR add index FKA54215FE7708282F (PERSON_ID), add constraint FKA54215FE7708282F foreign key (PERSON_ID) references PERSON (PERSON_ID) 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: alter table PERSON_EMAIL_ADDR add index FKA54215FE7708282F (PERSON_ID), add constraint FKA54215FE7708282F foreign key (PERSON_ID) references PERSON (PERSON_ID) 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - alter table PERSON_EVENT add index FKAD91D910F96D1A45 (EVENT_ID), add constraint FKAD91D910F96D1A45 foreign key (EVENT_ID) references EVENTS (EVENT_ID) 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: alter table PERSON_EVENT add index FKAD91D910F96D1A45 (EVENT_ID), add constraint FKAD91D910F96D1A45 foreign key (EVENT_ID) references EVENTS (EVENT_ID) 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 DEBUG SchemaExport:303 - alter table PERSON_EVENT add index FKAD91D9107708282F (PERSON_ID), add constraint FKAD91D9107708282F foreign key (PERSON_ID) references PERSON (PERSON_ID) 21:03:41,578 ERROR SchemaExport:274 - Unsuccessful: alter table PERSON_EVENT add index FKAD91D9107708282F (PERSON_ID), add constraint FKAD91D9107708282F foreign key (PERSON_ID) references PERSON (PERSON_ID) 21:03:41,578 ERROR SchemaExport:275 - No database selected 21:03:41,578 INFO SchemaExport:196 - schema export complete Hibernate: insert into USER (firstname, lastname, email, password, login, EVENT_DATE) values (?, ?, ?, ?, ?, ?) 21:03:41,734 WARN JDBCExceptionReporter:77 - SQL Error: 1046, SQLState: 3D000 21:03:41,734 ERROR JDBCExceptionReporter:78 - No database selected Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [webShop.User] 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 webShop.Manager.createAndStoreUser(Manager.java:45) at webShop.Manager.main(Manager.java:16) Caused by: java.sql.SQLException: No database selected at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2934) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1616) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1708) at com.mysql.jdbc.Connection.execSQL(Connection.java:3255) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1293) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1566) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1480) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1465) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33) ... 23 more
|
Подскажите , что исправить в конфиг файле?
|