I have the following two classes
public class A {
int id;
String name;
Set set = new HashSet();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set getSet() {
return set;
}
public void setSet(Set set) {
this.set = set;
}
public void addSet(B b){
this.set.add(b);
}
}
************************************
<class name="A" table="A" >
<id name="id" column="a_id" type="integer">
<generator class="increment" />
</id>
<property name="name" type="string" />
<set name="set" table="A_B">
<key column="a_id"/>
<one-to-many class="B"/>
</set>
</class>
***************************************
public class B {
private int id;
private String email;
private A a;
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
***********************
<class name="B" table="B" >
<id name="id" column="b_id" type="integer">
<generator class="increment" />
</id>
<property name="email" />
<many-to-one name="a" class="A" column="a_id" />
</class>
**********************************
My test class is as follows
public class Test {
public static void main(String[] args) {
A a = new A();
B b = new B();
B c= new B();
Transaction tx = null;
Session session = null;
a.setName("a");
b.setEmail("bmail");
b.setA(a);
c.setEmail("cmail");
c.setA(a);
a.addSet(b);
a.addSet(c);
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
tx = session.beginTransaction();
session.save(b);
session.save(c);
session.save(a);
tx.commit();
}
catch (Exception e){
System.out.println(e.getMessage());
}
finally{
session.close();
}
}
}
when I run the build.xml file, I get the following output error
[java] Example Test
[java] INFO - Hibernate 3.1 rc1
[java] INFO - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.dialect=org.hibernate.dialect.MySQLMyISAMDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:mysql://localhost/test, hibernate.show_sql=true, hibernate.connection.password=****, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
[java] INFO - using java.io streams to persist binary types
[java] INFO - using CGLIB reflection optimizer
[java] INFO - using JDK 1.4 java.sql.Timestamp handling
[java] INFO - configuring from resource: /hibernate.cfg.xml
[java] INFO - Configuration resource: /hibernate.cfg.xml
[java] INFO - Reading mappings from resource: A.hbm.xml
[java] INFO - Mapping class: A -> A
[java] INFO - Reading mappings from resource: B.hbm.xml
[java] INFO - Mapping class: B -> B
[java] INFO - Configured SessionFactory: null
[java] INFO - processing extends queue
[java] INFO - processing collection mappings
[java] INFO - Mapping collection: A.set -> B
[java] INFO - processing association property references
[java] INFO - processing foreign key constraints
[java] INFO - Using Hibernate built-in connection pool (not for production use!)
[java] INFO - Hibernate connection pool size: 10
[java] INFO - autocommit mode: false
[java] INFO - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test
[java] INFO - connection properties: {user=root, password=****}
[java] INFO - RDBMS: MySQL, version: 4.1.14-nt
[java] INFO - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.6 ( $Date: 2004/12/09 15:57:25 $, $Revision: 1.27.4.52 $ )
[java] INFO - Using dialect: org.hibernate.dialect.MySQLDialect
[java] INFO - Using default transaction strategy (direct JDBC transactions)
[java] INFO - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
[java] INFO - Automatic flush during beforeCompletion(): disabled
[java] INFO - Automatic session close at end of transaction: disabled
[java] INFO - JDBC batch size: 15
[java] INFO - JDBC batch updates for versioned data: enabled
[java] INFO - Scrollable result sets: enabled
[java] INFO - JDBC3 getGeneratedKeys(): enabled
[java] INFO - Connection release mode: null
[java] INFO - Maximum outer join fetch depth: 1
[java] INFO - Default batch fetch size: 1
[java] INFO - Generate SQL with comments: disabled
[java] INFO - Order SQL updates by primary key: disabled
[java] INFO - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[java] INFO - Using ASTQueryTranslatorFactory
[java] INFO - Query language substitutions: {no='N', yes='Y'}
[java] INFO - Second-level cache: enabled
[java] INFO - Query cache: disabled
[java] INFO - Cache provider: org.hibernate.cache.HashtableCacheProvider
[java] INFO - Optimize cache for minimal puts: disabled
[java] INFO - Cache region prefix: hibernate.test
[java] INFO - Structured second-level cache entries: disabled
[java] INFO - Echoing all SQL to stdout
[java] INFO - Statistics: disabled
[java] INFO - Deleted entity synthetic identifier rollback: disabled
[java] INFO - Default entity-mode: POJO
[java] INFO - building session factory
[java] INFO - Not binding factory to JNDI, no JNDI name configured
[java] INFO - Running hbm2ddl schema update
[java] INFO - fetching database metadata
[java] INFO - updating schema
[java] INFO - processing extends queue
[java] INFO - processing collection mappings
[java] INFO - processing association property references
[java] INFO - processing foreign key constraints
[java] INFO - table not found: A
[java] INFO - table not found: B
[java] INFO - table not found: A
[java] INFO - table not found: B
[java] ERROR - Unsuccessful: create table A (a_id integer not null, name varchar(255), primary key (a_id))
[java] ERROR - Can't find file: '.\test\a.frm' (errno: 13)
[java] ERROR - Unsuccessful: alter table B add index FK422D89FA (a_id), add constraint FK422D89FA foreign key (a_id) references A (a_id)
[java] ERROR - Can't create table '.\test\#sql-12c_5e.frm' (errno: 150)
[java] INFO - schema update complete
[java] INFO - cleaning up connection pool: jdbc:mysql://localhost/test
[java] INFO - Checking 0 named queries
[java] Hibernate:
[java] select
[java] max(b_id)
[java] from
[java] B
[java] Hibernate:
[java] select
[java] max(a_id)
[java] from
[java] A
[java] WARN - SQL Error: 1017, SQLState: HY000
[java] ERROR - Can't find file: '.\test\a.frm' (errno: 13)
[java] could not fetch initial value for increment generator
BUILD SUCCESSFUL
I am not sure where the actual problem is.
|