Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
yml configuration file:
jpa:
database: MYSQL
show-sql: true
hibernate:
ddl-auto: update #validate | update | create | create-drop
naming:
strategy: org.hibernate.cfg.DefaultNamingStrategy
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL5Dialect #Hibernate方言
Entity Class Resolution
annotation | effect |
---|---|
@GeneratorValue | JPA general policy generator |
@entity | Modifying one entity class, as receiving a name attribute of the entity class name, class name can be abbreviated as defaults |
@Table | Specify persistent class mapping table name |
@ID | id |
Dao layer:
public interface RoleDao extends JpaRepository<Role, Integer>{
@Query(value="select r.* from t_user u,t_user_role ur,t_role r where u.id=ur.role_id and ur.role_id=r.id and u.user_name=?1",nativeQuery=true)
List<Role> getRolesByUserName(String userName);
}
Compared to the mapper mapping mybatis file directly here annotation as a method of execution of SQL is not yet a beginning to adapt ...
annotation | effect |
---|---|
Query | Check for phrases |
Insert | Increased sentence |
delete | Delete statement |
Update | Change statement |
Finally, pom-dependent:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- 添加Hibernate依赖 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<!-- 添加Log4J依赖 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.6.4</version>
</dependency>
<!-- 添加javassist -->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.0.GA</version>
</dependency>
<!-- mysql数据库的驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>