JPA的一个重要特性:它是基于POJO的。
通过JDK5.0注解或XML描述对象—关系表的映射关系,并将运行期的实体对象持久化到数据库中
JPA包括以下3方面的技术
1.ORM映射元数据
2.JPA的API,操作实体对象,执行CRUD操作。
3.查询语句
JPA的查询语句
select distinct t from Topic t where t.topicTitle = ?1
select distinct t from Topic t where t.topicTitle = :title
等价写法
select distinct p from PollTopic p join p.options o
where o.optionItem like ?1
select distinct p from PollTopic p
where p.options.optionItem like ??1
从one到many
关联查询 : select distinct p from PollTopic p in(p.options) o where o.optionItem like ?1
对应的SQL语句:
select distinct t.topic_id,t.topic_type,t.topic_title,t.topic_time,t.topic_views,t.multiple,t.max_choices from t_topic t,t_poll_option t1 where (((t1.option_item like ?) and (t.topic_type=?)) and (t1.topic_id = t.topic_id))
从many到one
select p from PollOption p join p.PollTopic t where t.topicId = :topicId
sql语句: select t.option_id,t.option_item... from T_poll_option t, Topic t1
where ((t1.topic_id = ?) and ((t1.topic_id=t.topic_id) and (( t1_topic_type =?)))
通过JDK5.0注解或XML描述对象—关系表的映射关系,并将运行期的实体对象持久化到数据库中
JPA包括以下3方面的技术
1.ORM映射元数据
2.JPA的API,操作实体对象,执行CRUD操作。
3.查询语句
JPA的查询语句
select distinct t from Topic t where t.topicTitle = ?1
select distinct t from Topic t where t.topicTitle = :title
等价写法
select distinct p from PollTopic p join p.options o
where o.optionItem like ?1
select distinct p from PollTopic p
where p.options.optionItem like ??1
从one到many
关联查询 : select distinct p from PollTopic p in(p.options) o where o.optionItem like ?1
对应的SQL语句:
select distinct t.topic_id,t.topic_type,t.topic_title,t.topic_time,t.topic_views,t.multiple,t.max_choices from t_topic t,t_poll_option t1 where (((t1.option_item like ?) and (t.topic_type=?)) and (t1.topic_id = t.topic_id))
从many到one
select p from PollOption p join p.PollTopic t where t.topicId = :topicId
sql语句: select t.option_id,t.option_item... from T_poll_option t, Topic t1
where ((t1.topic_id = ?) and ((t1.topic_id=t.topic_id) and (( t1_topic_type =?)))