Issue Type: Bug Bug
Affects Versions: 4.1.8
Assignee: Unassigned
Created: 19/Nov/12 9:53 AM
Description:

There are two issues:

Issue 1; The field-mapping has the same name:

public class OneToManyHHH5836Test extends BaseCoreFunctionalTestCase {

	@Test
	public void testMappingWithSameNameFails() {
	}

	 @Override
	 protected Class[] getAnnotatedClasses() {
		 return new Class[] {Company.class, Person.class, EmailAddress.class};
	 }

	@Entity
	@Table(name = "company")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "company_id_seq", allocationSize = 1)
	public static class Company {
		@Id
		@Column(name = "id")
		@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
		private Long id = null;
		@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
		@JoinColumn(name = "recipient_id", nullable = false)
		List<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
	}

	@Entity
	@Table(name = "person")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "person_id_seq", allocationSize = 1)
	public static class Person {
		@Id
		@Column(name = "id")
		@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
		private Long id = null;
		@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
		@JoinColumn(name = "recipient_id", nullable = false)
		List<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
	}

	@Entity
	@Table(name = "email_address")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "email_address_id_seq", allocationSize = 1)
	public class EmailAddress {
		@Id
		@Column(name = "id")
		@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
		private Long id = null;
		@Column(name = "adress")
		String address = null;
	}

}

Fails with:
Caused by: org.hibernate.MappingException: Duplicate property mapping of _emailAddresses_recipient_idBackref found in org.hibernate.test.annotations.derivedidentities.e1.b.specjmapid.ondemand.OneToManyHHH5836Test$EmailAddress

Issue 2: The field-mapping has different name:

public class OneToManyHHH5836Test extends BaseCoreFunctionalTestCase {

	@Test
	public void testMappingWithSameNameFails() {
	}

	 @Override
	 protected Class[] getAnnotatedClasses() {
		 return new Class[] {Company.class, Person.class, EmailAddress.class};
	 }

	@Entity
	@Table(name = "company")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "company_id_seq", allocationSize = 1)
	public static class Company {
		@Id
		@Column(name = "id")
		@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
		private Long id = null;
		@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
		@JoinColumn(name = "recipient_id", nullable = false)
		List<EmailAddress> emailCompanyAddresses = new ArrayList<EmailAddress>();
	}

	@Entity
	@Table(name = "person")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "person_id_seq", allocationSize = 1)
	public static class Person {
		@Id
		@Column(name = "id")
		@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
		private Long id = null;
		@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
		@JoinColumn(name = "recipient_id", nullable = false)
		List<EmailAddress> emailPersonAddresses = new ArrayList<EmailAddress>();
	}

	@Entity
	@Table(name = "email_address")
	@SequenceGenerator(name = "SEQ_STORE", sequenceName = "email_address_id_seq", allocationSize = 1)
	public class EmailAddress {
		@Id
		@Column(name = "id")
		@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
		private Long id = null;
		@Column(name = "adress")
		String address = null;
	}

}

Fails with:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: org.hibernate.test.annotations.derivedidentities.e1.b.specjmapid.ondemand.OneToManyHHH5836Test$EmailAddress column: recipient_id (should be mapped with insert="false" update="false")

Project: Hibernate ORM
Priority: Major Major
Reporter: Andreas Joseph Krogh
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira