<context:annotation-config />
<context:component-scan base-package="org. springframework.samples. petclinic.web"/>
@Repository(value="") -
dao class anotation
@Service(value = "") - service class
anotation
@Component(value="") - bean class
anotation
@SpringBean(name ="servicebeanname") - to use service in apache wicket pages
Hibernate annotations
Hibernate supports the three basic inheritance mapping strategies:
table per class hierarchy - @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
table per subclass - @Inheritance(strategy = InheritanceType.JOINED)
table per concrete class - @Inheritance(strategy = InheritanceType.TABLE_PER_ CLASS)
In addition, Hibernate supports a fourth, slightly different kind of polymorphism:
implicit polymorphism
It
is possible to use different mapping strategies for different branches
of the same inheritance hierarchy. You can
then make use of implicit polymorphism to achieve polymorphism across
the whole hierarchy. However, Hibernate does not support mixing
<subclass>
,
<joined-subclass>
and
<union-subclass>
mappings under the same root
<class>
element. It is possible to mix together the table per hierarchy and
table per subclass strategies under the the same
<class>
element, by combining the
<subclass>
and
<join>
elements (see below for an example).
It is possible to define
subclass
,
union-subclass
, and
joined-subclass
mappings in separate mapping documents directly beneath
hibernate-mapping
. This allows you to extend a class hierarchy by adding
a new mapping file. You must specify an extends
attribute in the subclass
mapping, naming a previously mapped superclass. Previously
this feature made the ordering of the mapping documents important.
Since Hibernate3, the ordering of mapping files is irrelevant when using
the extends keyword. The ordering
inside a single mapping file still needs to be defined as superclasses before subclasses.
@Entity
@Table(name =
"")
@NamedQueries({
@NamedQuery(name =
"nameofthequery",
query =
"hibernatequery"),
@NamedQuery(name =
"nameofthequery",
query =
"hibernatequery")
})
@Id
@GeneratedValue(strategy =
GenerationType.IDENTITY)
@Column(name =
"tablecolumnname", unique =
true,
nullable = false)
private Integer
id;
@ManyToOne(cascade ={CascadeType.PERSIST,
CascadeType.MERGE,
CascadeType.REFRESH},fetch=Fet chType.EAGER)
@JoinColumn(name="
tablecolumnname",
nullable=false)
@ManyToOne(cascade =
CascadeType.REFRESH,fetch=Fetc hType.EAGER)
@JoinColumn(name="
tablecolumnname",
nullable=false)
@Column(name="
tablecolumnname",
nullable=false, length=20)
private String
name;
@Temporal(
TemporalType.DATE)
@Column(name="
tablecolumnname",
nullable=false)
private Date
varDate;
@ManyToOne(cascade =
CascadeType.REFRESH,fetch=Fetc hType.EAGER)
@JoinColumn(name="
tablecolumnname")
private A
a;
@OneToMany(mappedBy="A")
private List<A>
list;
@ManyToOne(cascade = {CascadeType.PERSIST,
CascadeType.MERGE,
CascadeType.REFRESH},fetch=Fet chType.EAGER)
@JoinColumn(name="
tablecolumnname",
nullable=false,
insertable=false, updatable=false)
private A
a;
@OneToMany(cascade = {CascadeType.PERSIST,
CascadeType.MERGE,
CascadeType.REFRESH},
mappedBy = "xxx")
//@OneToMany(mappedBy="xxx")
private List<Organization>
yyy;
@ManyToMany(mappedBy="zzz")
private List<vvv>
vvv;
@ManyToMany(cascade = {CascadeType.PERSIST,
CascadeType.MERGE,
CascadeType.REFRESH},fetch =
FetchType.LAZY)
@JoinTable(name =
"tablename",
joinColumns =
{
@JoinColumn(name =
"tanlecolumn",
nullable = false,
updatable =
false) },
inverseJoinColumns =
{
@JoinColumn(name =
"tablecolumn",
nullable = false, updatable =
false) })
private List<yyy>
yyyy;
complex id
----------
@EmbeddedId
PKClass
id;
@Embeddable
public
static
class
PKClass implements
Serializable {
private
static
final
long
serialVersionUID = 1L;
@Column(name="
tablecolumnname ", unique=true,
nullable=false)
private
int
a1;
@Column(name="
tablecolumnname", unique=true,
nullable=false)
private
int
a2;
public
PKClass () {
}
public
int
getXXX() {
return XXX;
}
public
void
setXXX(int XXX) {
this.XXX
= XXXX;
}
public
int
getXXX() {
return
XXX;
}
public
void
setXXX(int XXX) {
this.XXX
= XXX;
}
public
boolean equals(Object other) {
if (this
== other) {
return
true;
}
if (!(other
instanceof
PKClass)) {
return
false;
}
PKClass castOther = (PKClass)other;
return
(this.XXXX
== castOther.XXXX)
&& (this.XXX
== castOther.XXX);
}
public
int
hashCode() {
final
int prime = 31;
int hash = 17;
hash = hash * prime +
this.XXXX;
hash = hash * prime +
this.XXX;
return hash;
}
}
Query examples:
No comments:
Post a Comment