I have a file where I'm counting votes. I want to limit each user to a single vote on a given competition. The user can return and change his/her vote, but it would update the choice of competitor in the competition.
I can't figure out how to do this using Hibernate mapping files. (The programming language is Java.)
I've looked at using composite-id, but I want to have a typical numeric primary key on this thing if I need it later. (I also couldn't figure out how to make that work! =)
Here's my mapping file from which I generate the model objects and SQL:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.example.project.model.db.Vote" table="vote">
<id name="voteId" type="int">
<meta attribute="scope-set">protected</meta>
<meta attribute="use-in-equals">true</meta>
<generator class="native" />
</id>
<many-to-one name="user" column="userId" unique="false" not-null="true" lazy="false"
class="com.example.project.model.db.User"
/>
<many-to-one name="competition" column="competitionId" unique="false" not-null="true" lazy="false"
class="com.example.project.model.db.Competition"
/>
<many-to-one name="competitor" column="competitorId" unique="false" not-null="true" lazy="false"
class="com.example.project.model.db.Competitor"
/>
<property name="dateAdded" type="date" not-null="true" />
</class>
</hibernate-mapping>