import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
//import javax.persistence.NamedNativeQueries;
//import javax.persistence.NamedNativeQuery;
//import javax.persistence.NamedQueries;
@Column(name="id", updatable=false, nullable=false)
private Long id;
- @OneToMany(mappedBy="ad", fetch=FetchType.LAZY,
- cascade = CascadeType.ALL, targetEntity=AdDescription.class)
+// 1. Using just OneToMany:
+// @OneToMany(mappedBy="ad", fetch=FetchType.LAZY,
+// cascade = CascadeType.ALL, targetEntity=AdDescription.class)
+// 2. The same using @OneToMany + @JoinTable:
+ @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, targetEntity=AdDescription.class)
+ @JoinTable(
+ name="ad_description",
+ joinColumns = @JoinColumn( name="id"),
+ inverseJoinColumns = @JoinColumn( name="ad_id")
+ )
private Set<AdDescription> adDescriptions;
@Max(60)
<context:annotation-config />\r
\r
<context:component-scan base-package="de.spring.example.persistence" />\r
- \r
- <context:property-placeholder location="classpath:jpa.properties" />\r
- \r
+ \r
<bean id="entityManagerFactory"\r
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">\r
<property name="dataSource" ref="dataSource" />\r