-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an Hibernate ORM codestart #20879
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...ts/quarkus/extension-codestarts/hibernate-orm-codestart/base/README.tpl.qute.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{#include readme-header /} |
4 changes: 4 additions & 0 deletions
4
...rkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
quarkus: | ||
hibernate-orm: | ||
database: | ||
generation: drop-and-create |
5 changes: 5 additions & 0 deletions
5
...s/quarkus/extension-codestarts/hibernate-orm-codestart/base/src/main/resources/import.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- This file allow to write SQL commands that will be emitted in test and dev. | ||
-- The commands are commented as their support depends of the database | ||
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-1'); | ||
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-2'); | ||
-- insert into myentity (id, field) values(nextval('hibernate_sequence'), 'field-3'); |
12 changes: 12 additions & 0 deletions
12
...n/resources/codestarts/quarkus/extension-codestarts/hibernate-orm-codestart/codestart.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: hibernate-orm-codestart | ||
ref: hibernate-orm | ||
tags: extension-codestart | ||
type: code | ||
metadata: | ||
title: Hibernate ORM | ||
description: Create your first JPA entity | ||
related-guide-section: https://quarkus.io/guides/hibernate-orm | ||
language: | ||
base: | ||
dependencies: | ||
- io.quarkus:quarkus-hibernate-orm |
47 changes: 47 additions & 0 deletions
47
...us/extension-codestarts/hibernate-orm-codestart/java/src/main/java/org/acme/MyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.acme; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
/** | ||
* Example JPA entity. | ||
* | ||
* To use it, get access to a JPA EntityManager via injection. | ||
* | ||
* {@code | ||
* @Inject | ||
* EntityManager em; | ||
* | ||
* public void doSomething() { | ||
* MyEntity entity1 = new MyEntity(); | ||
* entity1.setField("field-1"); | ||
* em.persist(entity1); | ||
* | ||
* List<MyEntity> entities = em.createQuery("from MyEntity", MyEntity.class).getResultList(); | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
public class MyEntity { | ||
private Long id; | ||
private String field; | ||
|
||
@Id | ||
@GeneratedValue | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setField(String field) { | ||
this.field = field; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...sion-codestarts/hibernate-orm-codestart/kotlin/src/main/kotlin/org/acme/MyKotlinEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.acme | ||
|
||
import javax.persistence.Entity | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.Id | ||
|
||
/** | ||
* Example JPA entity. | ||
* | ||
* To use it, get access to a JPA EntityManager via injection. | ||
* | ||
* {@code | ||
* @Inject | ||
* lateinit var em:EntityManager; | ||
* | ||
* fun doSomething() { | ||
* val entity1 = MyKotlinEntity(); | ||
* entity1.field = "field-1" | ||
* em.persist(entity1); | ||
* | ||
* val entities:List<MyKotlinEntity> = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinEntity { | ||
@get:GeneratedValue | ||
@get:Id | ||
var id: Long? = null | ||
var field: String? = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...tools/src/test/java/io/quarkus/devtools/codestarts/quarkus/HibernateOrmCodestartTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||
package io.quarkus.devtools.codestarts.quarkus; | ||||||
|
||||||
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA; | ||||||
|
||||||
import org.junit.jupiter.api.Test; | ||||||
import org.junit.jupiter.api.extension.RegisterExtension; | ||||||
|
||||||
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest; | ||||||
import io.quarkus.maven.ArtifactKey; | ||||||
|
||||||
public class HibernateOrmCodestartTest { | ||||||
|
||||||
@RegisterExtension | ||||||
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest.builder() | ||||||
.codestarts("hibernate-orm") | ||||||
.extension(new ArtifactKey("io.quarkus", "quarkus-jdbc-h2")) | ||||||
.languages(JAVA) | ||||||
.build(); | ||||||
|
||||||
@Test | ||||||
void testContent() throws Throwable { | ||||||
codestartTest.checkGeneratedSource("org.acme.MyEntity"); | ||||||
codestartTest.checkGeneratedSource(QuarkusCodestartCatalog.Language.KOTLIN, "org.acme.MyKotlinEntity"); | ||||||
} | ||||||
|
||||||
@Test | ||||||
void buildAllProjectsForLocalUse() throws Throwable { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
codestartTest.buildAllProjects(); | ||||||
} | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...pshots__/HibernateOrmCodestartTest/testContent/src_main_java_ilove_quark_us_MyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ilove.quark.us; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
/** | ||
* Example JPA entity. | ||
* | ||
* To use it, get access to a JPA EntityManager via injection. | ||
* | ||
* {@code | ||
* @Inject | ||
* EntityManager em; | ||
* | ||
* public void doSomething() { | ||
* MyEntity entity1 = new MyEntity(); | ||
* entity1.setField("field-1"); | ||
* em.persist(entity1); | ||
* | ||
* List<MyEntity> entities = em.createQuery("from MyEntity", MyEntity.class).getResultList(); | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
public class MyEntity { | ||
private Long id; | ||
private String field; | ||
|
||
@Id | ||
@GeneratedValue | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public void setField(String field) { | ||
this.field = field; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...__/HibernateOrmCodestartTest/testContent/src_main_kotlin_ilove_quark_us_MyKotlinEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ilove.quark.us | ||
|
||
import javax.persistence.Entity | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.Id | ||
|
||
/** | ||
* Example JPA entity. | ||
* | ||
* To use it, get access to a JPA EntityManager via injection. | ||
* | ||
* {@code | ||
* @Inject | ||
* lateinit var em:EntityManager; | ||
* | ||
* fun doSomething() { | ||
* val entity1 = MyKotlinEntity(); | ||
* entity1.field = "field-1" | ||
* em.persist(entity1); | ||
* | ||
* val entities:List<MyKotlinEntity> = em.createQuery("from MyEntity", MyKotlinEntity::class.java).getResultList() | ||
* } | ||
* } | ||
*/ | ||
@Entity | ||
class MyKotlinEntity { | ||
@get:GeneratedValue | ||
@get:Id | ||
var id: Long? = null | ||
var field: String? = null | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to use a kotlin
data
object?