-->
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.  [ 4 posts ] 
Author Message
 Post subject: Bug using Mysql dialect with annotations?
PostPosted: Tue Aug 23, 2005 8:51 am 
Newbie

Joined: Thu Aug 18, 2005 12:24 pm
Posts: 11
Hibernate version:3.1

PROBLEM: Im exporting my schema based on my bean classes ( top-down ), and it is almost perfect except for the fact that the annotation @OnDelete has no effect when used with mysql dialect. It is a simple test program.. here's what I've done:

It is a tipical OneToMany schema:

A classe named book:

@Entity
@Table(name="book")
public class Book
implements Serializable
{
... ...
...

@Id(generate=GeneratorType.AUTO)
@NotNull
public java.lang.Integer getId()
{
return id;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn( name="customer_fk" )
@OnDelete(action=OnDeleteAction.CASCADE)
public Customer getCustomer()
{
return this.customer;
}
...

and a class customer:

@Entity
@Table(name="customer")
public class Customer
implements Serializable
{
...
...

@Id(generate=GeneratorType.AUTO)
public Integer getId()
{
return this.id;
}

@OneToMany( mappedBy="customer" )
public List<Book> getBooks()
{
return this.books;
}
...

and, then I export schema like this:

...
try
{
cfg = new AnnotationConfiguration( );

// database connection and dialect settings
cfg.configure( CONFIG_FILE_LOCATION );

cfg.addAnnotatedClass( Book.class );
cfg.addAnnotatedClass( Customer.class );


SchemaExport se = new SchemaExport( cfg );
se.create( true , true );
}

and it generates a schema in DDL like this:

create table book (
id integer not null auto_increment,
author varchar(255),
available bit not null,
title varchar(255),
customer_fk integer,
primary key (id)
)
create table customer (
id integer not null auto_increment,
lastname varchar(255),
age integer,
name varchar(255),
primary key (id)
)
alter table book
add index FK2E3AE9C95247C0 (customer_fk),
add constraint FK2E3AE9C95247C0
foreign key (customer_fk)
references customer (id)


BUT... it puts no integrity restriction on foreign key constraint, like 'ON DELETE CASCADE' as it should ( because of my @OnDelete annotation in book class ), so, what happens is that the database gets inconsistent everytime a customer is erased from database... and plus, there is no annotation like OnDeleteAction.SETNULL, there is only NO_ACTION or CASCADE.. what happened with SETNULL? Its very important...

Does anybody can help me using some integrity restriction like ON DELETE SET NULL and finding why SchemaExport ignores my @OnDelete annotation ?

Help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 3:40 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
There are more than one mysql dialect: MySQLDialect, MySQLMyISAMDialect, and MySQLInnoDBDialect. You must use the last to support transactions and integrity.

King regards

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
 Post subject: And how to use SET NULL?
PostPosted: Tue Aug 23, 2005 4:19 pm 
Newbie

Joined: Thu Aug 18, 2005 12:24 pm
Posts: 11
Hi, thank you very much for your help!
But I noticed that there is no @OnDeleteAction(action=DeleteAction.SETNULL)...
How to implement SETNULL integrity restriction?

I really want to know that!
An thank you again!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 23, 2005 9:43 pm 
Regular
Regular

Joined: Thu Jul 08, 2004 1:21 pm
Posts: 68
Location: Recife - Pernambuco - Brazil
As far as I know, there is no action to do it. But you can implement an interceptor/listernet to do it for you. Anyway, you could submit a jira issue.

hth

_________________
Marcos Silva Pereira
http://blastemica.blogspot.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.