日期:2014-05-19  浏览次数:20777 次

(翻译)Spring到Java EE的迁移(一)__续

续前节。

?

我们看到,NetBeans通过自动生成JPA实体为我们节省了大量时间。?“Don’t use wizard code you don’t understand.”———Andrew Hunt and Dave Thomas

?

咱们看看生成的实体代码,你自己理解一下。

Listing 1. Examining a Generated Entity

package com.ensode.petclinicjavaee.entity; ? //imports omitted for brevity ??@Entity
@Table(name = "owners", catalog = "petclinic", schema = "")
@XmlRootElement
@NamedQueries({
? ? @NamedQuery(name = "Owner.findAll", query = "SELECT o FROM Owner o"),
? ? @NamedQuery(name = "Owner.findById",
? ? ? ? query = "SELECT o FROM Owner o WHERE o.id = :id"),
? ? @NamedQuery(name = "Owner.findByFirstName",
? ? ? ? query = "SELECT o FROM Owner o WHERE o.firstName = :firstName"),
? ? @NamedQuery(name = "Owner.findByLastName",
? ? ? ? query = "SELECT o FROM Owner o WHERE o.lastName = :lastName"),
? ? @NamedQuery(name = "Owner.findByAddress",
? ? ? ? query = "SELECT o FROM Owner o WHERE o.address = :address"),
? ? @NamedQuery(name = "Owner.findByCity",
? ? ? ? query = "SELECT o FROM Owner o WHERE o.city = :city"),
? ? @NamedQuery(name = "Owner.findByTelephone",
? ? ? ? query = "SELECT o FROM Owner o WHERE o.telephone = :telephone")})
?public class Owner implements Serializable { ? ? private static final long serialVersionUID = 1L; ? ??@Id
? ? @GeneratedValue(strategy = GenerationType.IDENTITY)
? ??@Basic(optional = false)
? ? @NotNull
? ? @Column(name = "id", nullable = false)
?? ? private Integer id; ? ??@Size(max = 30)
? ? @Column(name = "first_name", length = 30)
? ? private String firstName; ? ??@Size(max = 30)
? ? @Column(name = "last_name", length = 30)
? ? private String lastName; ? ??@Size(max = 255)
? ? @Column(name = "address", length = 255)
? ? private String address; ? ?