Enhancement 210 : ENHANCEMENT: Extend the NamingConvention to support ... where PK and FK the same
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.4.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
27/01/2010
Updated 
27/01/2010
Type 
Enhancement
 
Attachments 
No attachments

Added a method

/**
     * Return true if a prefix should be used building a foreign key name.
     * <p>
     * This by default is true and this works well when the primary key column
     * names are simply "ID". In this case a prefix (such as "ORDER" and
     * "CUSTOMER" etc) is added to the foreign key column producing "ORDER_ID"
     * and "CUSTOMER_ID".
     * </p>
     * <p>
     * This should return false when your primary key columns are the same as
     * the foreign key columns. For example, when the primary key columns are
     * "ORDER_ID", "CUST_ID" etc ... and they are the same as the foreign key
     * column names.
     * </p>
     */
    public boolean isUseForeignKeyPrefix();
 
Rob 27 Jan 07:35
ebean.properties

You can set useForeignKeyPrefix to false using ebean.properties

ebean.namingConvention.useForeignKeyPrefix=false

Rob 27 Jan 07:42
Example ..
@Entity
@Table(name="o_order")
public class Order {

    @Id
    @Column(name="ord_id")
    Integer id;
    
    String description;

    @ManyToOne
    Customer customer;
    
    @OneToMany
    List<OrderDetail> details;

...

@Entity
@Table(name="o_customer")
public class Customer {

    @Id
    @Column(name="cust_id")
    Integer id;

... with useForeignKeyPrefix=false the foreign key column is "cust_id"

... and note the fk column of cust_id ... is the same as the pk for the customer table.

select o.ord_id c0, o.description c1, o.cust_id c2
from o_order o

Rob 27 Jan 08:00
Fixed in HEAD

Fixed in HEAD.

woResponse

Upload a file