0

I have parent-child mapping in hibernate where the entities are connected through table.

The problem is that column automatically created by hibernate in this table is called like "_actions_id". But I use Oracle and it says that column name "_actions_id" is invalid.

It works fine when I wrap the name with "" and execute the script manually, but is there a way to make hibernate to wrap all columns with "" ?

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
Oleg
  • 575
  • 4
  • 13
  • Do you have to rely on the default names? If you don't, then you can specify the name using the `joinColumns` annotation property and create the column in the database manually. You can have quotes in the property as well. – billc.cn Jun 04 '12 at 23:53
  • Could you bring a simplest example? how are name and referencedColumnName are correlated? Should I specify 2 columns or just for the child entity? – Oleg Jun 05 '12 at 00:28

2 Answers2

1

In your example, you specified a join table, which is for scenarios like this

People table:
PID | Name
1   | Albert
2   | Bob


TelephoneNumbers table:
TID | Tel
1   | 123-456
2   | 456-789
3   | 789-012

Join table:
PID | TID
1   | 1
1   | 2
2   | 3

I.e. the column that connects the current entity to the entity in the collection is in neither the current table nor the table for the collection entity. This is more useful for the many-to-many mapping, but you can also use it for OneToMany if you don't have control over the TelephoneNumbers table for example. Otherwise you should just use plain @JoinColumn.

The usage of @JoinTable has been explained many times by many websites. See the JavaDoc and this question.

Community
  • 1
  • 1
billc.cn
  • 7,187
  • 3
  • 39
  • 79
0

I think you want a custom NamingStrategy. I got the idea here. In your case, it would be something like:

public class MyNamingStrategy extends DefaultNamingStrategy {
    public String logicalCollectionColumnName(String columnName, String propertyName, String referencedColumn) {
        return "`" + super.logicalCollectionColumnName(columnName, propertyName, referencedColumn + "`";
    }
}
John Watts
  • 8,717
  • 1
  • 31
  • 35