Thank you. Just tried that, but I'm running into errors when it tries to create
a table for an entity that is supposed to become a CHAR(1) field based on the
annotations in the entity, but it tries to generate the field as CHAR(255),
which it complains about. Here is a snippet of the entity and the log messages:
> @Entity
> @Table(name = "DISCOUNT_CODE")
> @XmlRootElement
> @NamedQueries({
> @NamedQuery(name = "DiscountCode.findAll", query = "SELECT d FROM
> DiscountCode d"),
> @NamedQuery(name = "DiscountCode.findByDiscountCode", query = "SELECT d
> FROM DiscountCode d WHERE d.discountCode = :discountCode"),
> @NamedQuery(name = "DiscountCode.findByRate", query = "SELECT d FROM
> DiscountCode d WHERE d.rate = :rate")})
> public class DiscountCode implements Serializable {
> private static final long serialVersionUID = 1L;
> @Id
> @Basic(optional = false)
> @NotNull
> @Size(min = 1, max = 1)
> @Column(name = "DISCOUNT_CODE")
> private String discountCode;
> // @Max(value=?) @Min(value=?)//if you know range of your decimal fields
> consider using these annotations to enforce field validation
> @Column(name = "RATE")
> private BigDecimal rate;
> @OneToMany(cascade = CascadeType.ALL, mappedBy = "discountCode", fetch =
> FetchType.EAGER)
> private Collection<Customer> customerCollection;
> SEVERE: EjbTransactionUtil.handleSystemException: The length, precision, or
> scale attribute for column, or type mapping 'CHAR(255)' is not valid. {stmnt
> 971815908 CREATE TABLE PRODUCT_CODE -- ProductCode
> (PROD_CODE VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255), DISCOUNT_CODE
> CHAR(255), PRIMARY KEY (PROD_CODE))} [code=30000, state=42611]
> <openjpa-2.4.0-nonfinal-1598334-r422266:1599166 nonfatal general error>
> org.apache.openjpa.persistence.PersistenceException: The length, precision,
> or scale attribute for column, or type mapping 'CHAR(255)' is not valid.
> {stmnt 971815908 CREATE TABLE PRODUCT_CODE -- ProductCode
> (PROD_CODE VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(255), DISCOUNT_CODE
> CHAR(255), PRIMARY KEY (PROD_CODE))} [code=30000, state=42611]
> at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:559)
> at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:455)
>
Any idea why that is? I mean there's a @Size annotation in the entity that tell
it the max size. Shouldn't the mapper tool take that into account?
Kay
> On Apr 24, 2015, at 10:59 AM, Jody Grassel <[email protected]> wrote:
>
> That directive will instruct OpenJPA to introspect the databases to ensure
> the tables needed for the table schema defined by your ORM exists, and will
> create the table structures automatically if they do not exist. Do you
> have a special need that requires OpenJPA to execute a provided SQL script?
>
> On Fri, Apr 24, 2015 at 10:54 AM, Kay Wrobel <[email protected]> wrote:
>
>> Thanks, Jody. How will that let me provide an SQL script containing CREATE
>> TABLE and INSERT statements?
>>
>> Kay
>>
>>> On Apr 24, 2015, at 10:51 AM, Jody Grassel <[email protected]> wrote:
>>>
>>> Add the following property to your persistence unit:
>>>
>>> <property name="openjpa.jdbc.SynchronizeMappings"
>>> value="buildSchema(ForeignKeys=true)"/>
>>>
>>>
>>>
>>> On Fri, Apr 24, 2015 at 10:47 AM, Kay Wrobel <[email protected]> wrote:
>>>
>>>> Hi everybody.
>>>>
>>>> I am having a rough time finding a way to initialize an Embedded
>> In-Memory
>>>> Derby database in my web application. I found a reference on Oracle's
>> web
>>>> site that states you can initialize a database with DDL and DML
>> statements
>>>> using properties like the following:
>>>>
>>>>> <properties>
>>>>> <property
>>>> name="javax.persistence.schema-generation.database.action"
>>>> value="drop-and-create"/>
>>>>> <property
>>>> name="javax.persistence.schema-generation.create-source"
>> value="script"/>
>>>>> <property
>>>> name="javax.persistence.schema-generation.create-script-source"
>>>> value="META-INF/sql/create.sql" />
>>>>> <property name="javax.persistence.sql-load-script-source"
>>>> value="META-INF/sql/data.sql" />
>>>>> </properties>
>>>>
>>>>
>>>> However, that seems to be a new feature in JPA 2.1 spec as part of JEE
>> 6.
>>>> I am working with OpenJPA provided by Apache TomEE, which is
>> openjpa-2.4.0
>>>> non-final, a JPA 2.0 implementation I would imagine. The current
>> release on
>>>> OpenJPA web site is openjpa 2.3.
>>>>
>>>> Is there a way to accomplish this via JPA 2.0 and/or OpenJPA
>> properties?
>>>> I am trying to initialize an in-memory database for a test case I try to
>>>> provide to someone.
>>>>
>>>> Any help would be much appreciated.
>>>>
>>>> Kay Wrobel
>>
>>