More Related Content Similar to Jpa hibernate and building customize library (knowledge share) (20) Jpa hibernate and building customize library (knowledge share)2. CREATE TABLE CLASS
• Annotations with Parameter:
• Entity
• Table(name, indexes*)
• Id
• Column(name, nullable, unique, updatable, length, columnDefinition)
• JoinColumn
• ManyToOne, OneToMany, OneToOne
• GenericGenerator(name, strategy)
• GeneratedValue(generator)
3. CREATE REPOSITORY INTERFACE
• Interface format:
• Public interface xxxRepository extends JpaRepostiory<xxx, (type of id)> *
• Annotations and Parameter:
• Query(value, nativeQuery)
• Param
• findBy… Method
• Component *
4. PACKAGE CUSTOMIZE LIBRARIES
• Edit pom.xml *
• Clean and build
• Install to local maven repository
• With IntellJ JDE
• Maven Projects -> Lifecycle -> install
• Other JDE
• Command prompt (cmd)
• cd to maven directory *
• Maven install *
5. USE CUSTOMIZE LIBRARY
• Edit pom.xml *
• Necessary Annotation:
• ComponentScan(basePackages = "io.sis.klaver.dbclass")
• EntityScan(basePackages = "io.sis.klaver.dbclass")
• EnableJpaRepositories(basePackages = "io.sis.klaver.dbclass")
• Autowired
6. SPRING DB CONNECTION AND CONFIG
• Datasource:
• Url
• Username
• Password
• JPA:
• Hibernate
• Ddl-auto (validate, update, create, create-drop) *
• Show_sql
Editor's Notes For table annotation indexes only works with create-drop
@JoinColumns(foreignKey = @ForeignKey(name = "FK_USER"); JpaRepository extends PagingAndSortingRepository extends CrudRepository extends Repository
For spring autowire <build> <plugins> <!-- any other plugins --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> <finalName>klaver-database</finalName></build>
Usually is C:\Program Files\apache-maven-3.3.9\bin
http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/ <dependency>
<groupId>{your groupid}</groupId>
<artifactId>{your artifactid}</artifactId>
<version>{your version}</version>
</dependency> validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema when the SessionFactory is closed explicitly, typically when the application is stopped.