forked from hibernate/hibernate-orm
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-10523 - 2.3.20. SQL quoted identifiers in User Guide should discu…
…ss explicit enclosure in double-quotes (JPA)
- Loading branch information
1 parent
cdb11f9
commit 80770ab
Showing
4 changed files
with
242 additions
and
3 deletions.
There are no files selected for viewing
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
2 changes: 2 additions & 0 deletions
2
...sciidoc/userguide/chapters/domain/extras/basic/basic-auto-quoting-persistence-example.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,2 @@ | ||
INSERT INTO "Product" ("name", "number", "id") | ||
VALUES ('Mobile phone', '123-456-7890', 1) |
95 changes: 95 additions & 0 deletions
95
documentation/src/test/java/org/hibernate/userguide/mapping/basic/AutoQuotingTest.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,95 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.userguide.mapping.basic; | ||
|
||
import java.util.Map; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.cfg.AvailableSettings; | ||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hibernate.userguide.util.TransactionUtil.doInJPA; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class AutoQuotingTest extends BaseEntityManagerFunctionalTestCase { | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[] { | ||
Product.class | ||
}; | ||
} | ||
|
||
@Override | ||
protected Map buildSettings() { | ||
Map settings = super.buildSettings(); | ||
settings.put( AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true ); | ||
return settings; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
doInJPA( this::entityManagerFactory, entityManager -> { | ||
//tag::basic-auto-quoting-persistence-example[] | ||
Product product = new Product(); | ||
product.setId( 1L ); | ||
product.setName( "Mobile phone" ); | ||
product.setNumber( "123-456-7890" ); | ||
entityManager.persist( product ); | ||
//end::basic-auto-quoting-persistence-example[] | ||
} ); | ||
} | ||
|
||
//tag::basic-auto-quoting-example[] | ||
@Entity(name = "Product") | ||
public static class Product { | ||
|
||
@Id | ||
private Long id; | ||
|
||
private String name; | ||
|
||
private String number; | ||
|
||
//Getters and setters are omitted for brevity | ||
|
||
//end::basic-auto-quoting-example[] | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(String number) { | ||
this.number = number; | ||
} | ||
|
||
|
||
//tag::basic-auto-quoting-example[] | ||
} | ||
//end::basic-auto-quoting-example[] | ||
} |
89 changes: 89 additions & 0 deletions
89
documentation/src/test/java/org/hibernate/userguide/mapping/basic/JpaQuotingTest.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,89 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.userguide.mapping.basic; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
|
||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hibernate.userguide.util.TransactionUtil.doInJPA; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class JpaQuotingTest extends BaseEntityManagerFunctionalTestCase { | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[] { | ||
Product.class | ||
}; | ||
} | ||
|
||
@Test | ||
public void test() { | ||
doInJPA( this::entityManagerFactory, entityManager -> { | ||
//tag::basic-jpa-quoting-persistence-example[] | ||
Product product = new Product(); | ||
product.setId( 1L ); | ||
product.setName( "Mobile phone" ); | ||
product.setNumber( "123-456-7890" ); | ||
entityManager.persist( product ); | ||
//end::basic-jpa-quoting-persistence-example[] | ||
} ); | ||
} | ||
|
||
//tag::basic-jpa-quoting-example[] | ||
@Entity(name = "Product") | ||
public static class Product { | ||
|
||
@Id | ||
private Long id; | ||
|
||
@Column(name = "\"name\"") | ||
private String name; | ||
|
||
@Column(name = "\"number\"") | ||
private String number; | ||
|
||
//Getters and setters are omitted for brevity | ||
|
||
//end::basic-jpa-quoting-example[] | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(String number) { | ||
this.number = number; | ||
} | ||
|
||
|
||
//tag::basic-jpa-quoting-example[] | ||
} | ||
//end::basic-jpa-quoting-example[] | ||
} |