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 "" ?

2
  • 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. Commented Jun 4, 2012 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? Commented Jun 5, 2012 at 0:28

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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 + "`";
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.