LINUX.ORG.RU

Вопрос решён. Поменял many-to-many на one-to-many и many-to-one и создал java-entity для промежуточной таблицы.

create table routes (id int8 not null, title varchar(255) not null, duration float8, primary key (id));
create table routes_stops (id int8 not null, pos int4 not null, stop_id int8 not null, route_id int8 not null, primary key (id), unique (pos, stop_id, route_id));
create table stops (id int8 not null, title varchar(255) not null, primary key (id));

	<class name="Stop" table="stops">
		<id name="id" column="id" type="long">
			<generator class="native"/>
		</id>
		
		<property name="title" type="string" length="255" not-null="true"/>
		
		<set name="routes" table="routes_stops" inverse="true">
			<key column="stop_id" />
			<one-to-many class="RoutesStops" />
		</set>
	</class>

	<class name="Route" table="routes">
		<id name="id" column="id" type="long">
			<generator class="native"/>
		</id>
		
		<property name="title" type="string" length="255" not-null="true"/>
		<property name="duration" type="double"/>
		
		<set name="stops" table="routes_stops" inverse="true">
			<key column="route_id" />
			<one-to-many class="RoutesStops" />
		</set>
	</class>

	<class name="RoutesStops" table="routes_stops">
		<id name="id" column="id" type="long">
			<generator class="native"/>
		</id>
		
		<property name="pos" column="pos" type="java.lang.Integer" unique-key="true" not-null="true"/>
		
		<many-to-one name="stop_id" class="Stop" unique-key="true" not-null="true" />
		<many-to-one name="route_id" class="Route" unique-key="true" not-null="true" />
	</class>

HappyCoder
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.