views:

290

answers:

1

Working on some legacy hibernate code.

How do I do the following with hbm.xml(hibernate mapping file) instead of with annotations?

@Table(name="users", uniqueConstraints = {
    @UniqueConstraint(columnNames={"username", "client"}),
    @UniqueConstraint(columnNames={"email", "client"})
})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    private int id;
    private String username;
    private String email;
    private Client client;
}
+1  A: 

use the properties tag :

...
<properties name="uk1" unique="true">
        <property name="username" .../>
        <many-to-one name="client" .../>
</properties>

<properties name="uk2" unique="true">
        <property name="email" .../>
        <many-to-one name="client" update="false" insert="false" .../>
</properties>
...

all available option describe here : http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-properties section 5.1.16

Thierry