How can I use the same change set with content for different databases?
<changeSet author="azare (generated)" id="some-data>
<insert tableName="some-table">
<column name="id" valueNumeric="1"/>
if h2
<column name="some-column" value="h2-val"/>
if postgresql
<column name="some-column" value="postgresql-val"/>
</insert>
</changeSet>
I found a way to solve this issue:
<property name="val" dbms="postgresql" value="postgresql-val"/>
<property name="val" dbms="h2" value="h2-val"/>
<changeSet author="azare (generated)" id="some-data">
<insert tableName="some-table">
<column name="id" valueNumeric="1"/>
<column name="some-column" value="${val}"/>
</insert>
</changeSet>
Related
My postgres looks really streng suddenly and I do not why! What are those pluses and dashes? The table is create via liquebase in spring. It looked normal before. Now my get requests are not working and I am not sure if it is relevant to this schema problem.
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">
<changeSet id="create_questionnaire_entity_11" author="Iman Gharib">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="questionnaire_entity"/>
</not>
</preConditions>
<createTable tableName="questionnaire_entity" schemaName="public">
<column name="id" autoIncrement="true" type="bigint"/>
<column name="patient_number" type="varchar"/>
<column name="questionnaire_id" type="varchar"/>
<column name="received_date" type="datetime"/>
<column name="question_type" type="varchar"/>
<column name="question_text" type="varchar"/>
</createTable>
<addPrimaryKey tableName="questionnaire_entity" columnNames="id"/>
</changeSet>
<changeSet id="extend_text_size_2" author="Iman Gharib">
<modifyDataType
columnName="question_text"
newDataType="varchar(2000)"
tableName="questionnaire_entity"/>
</changeSet>
</databaseChangeLog>
select * from the table:
id | patient_number | questionnaire_id | received_date | question_type |
question_text
------+----------------+-----------------------------+-------------------------+---------------+-------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'm using liquibase 3.5.5 with postgresql. All my tables are being created in a specified schema, however when liquibase tried to generate the DDL, it is appending "public." in front of the referencesTableName. I've tried making the table name "identity.users", but it just tries to create public."identity.users".
For example, the below
<createTable tableName="users" schemaName="identity">
<column name="id" type="bigint" defaultValueSequenceNext="seq_users">
<constraints primaryKey="true" primaryKeyName="pk_users"/>
</column>
</createTable>
<createTable tableName="external_identities" schemaName="identity">
<column name="id" type="bigint" defaultValueSequenceNext="seq_external_identities">
<constraints primaryKey="true" primaryKeyName="pk_external_identities"/>
</column>
<column name="user_id" type="bigint">
<constraints foreignKeyName="fk_external_identities_users" referencedTableName="users" referencedColumnNames="id" nullable="false"/>
</column>
</createTable>
Produces:
CREATE TABLE identity.external_identities (id BIGINT DEFAULT nextval('identity.seq_external_identities') NOT NULL, user_id BIGINT NOT NULL, CONSTRAINT fk_external_identities_users FOREIGN KEY (user_id) REFERENCES public.users(id))
The docs don't help much, and the XSD file does not list schema as an option:
<!-- Attributes for constraints -->
<xsd:attributeGroup name="constraintsAttributes">
<xsd:attribute name="nullable" type="booleanExp" />
<xsd:attribute name="primaryKey" type="booleanExp" />
<xsd:attribute name="primaryKeyName" type="xsd:string" />
<xsd:attribute name="primaryKeyTablespace" type="xsd:string" />
<xsd:attribute name="unique" type="booleanExp" />
<xsd:attribute name="uniqueConstraintName" type="xsd:string" />
<xsd:attribute name="references" type="xsd:string" />
<xsd:attribute name="referencedTableName" type="xsd:string"/>
<xsd:attribute name="referencedColumnNames" type="xsd:string"/>
<xsd:attribute name="foreignKeyName" type="xsd:string" />
<xsd:attribute name="deleteCascade" type="booleanExp" />
<xsd:attribute name="deferrable" type="booleanExp" />
<xsd:attribute name="initiallyDeferred" type="booleanExp" />
<xsd:attribute name="checkConstraint" type="xsd:string" />
</xsd:attributeGroup>
Try using separate changeset for adding foreign key constratint. It'll be addForeignKeyConstraint. It has schema attributes.
ChangeSet will look like this:
<changeSet author="liquibase-docs" id="addForeignKeyConstraint-example">
<addForeignKeyConstraint
baseColumnNames="user_id"
baseTableName="external_identities"
constraintName="fk_external_identities_users"
referencedColumnNames="id"
referencedTableName="users"
baseTableSchemaName="identity"
referencedTableSchemaName="identity"/>
</changeSet>
Had to use changeSet with sql like:
ALTER TABLE schema.table ADD CONSTRAINT constraint FOREIGN KEY (fk_field) REFERENCES schema.ref_table (field)
Support for specifying the referenced schema of a foreign key defined in the constraints element was added in version 3.5 of Liquibase. In version 3.5 of the dbchangelog XSD you can find the new referencedTableSchemaName attribute on the constraints element.
Liquibase will not recognize this new attribute if your changelog XML file still imports an older XSD version, so make sure that the databaseChangeLog root element references version 3.5 or newer of the XSD file:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
<!-- ... -->
</databaseChangeLog>
Then update the constraints element of your column definition with a value for the referencedTableSchemaName attribute:
<column name="user_id" type="bigint">
<constraints
foreignKeyName="fk_external_identities_users"
referencedTableSchemaName="identity"
referencedTableName="users"
referencedColumnNames="id"
nullable="false"/>
</column>
I need some help as I'm stumped on an Hibernate 4/Struts 2 project. This is my first Hibernate 4 (4.3.11) project, as I worked for years with Hibernate 3. The database is MySQL 5.
All mapping classes were produced with Hibernate Tools provided by JBoss Tools 4.3.5, on Eclipse Mars 2. No problem was encountered, it worked fine.
But when testing, I faced this exception :
2017-02-16 17:23:45 ERROR Dispatcher:38 - Exception occurred during processing request: metier.Ville_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
java.lang.ClassCastException: metier.Ville_$$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:147)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:75)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:771)
I read that post but I don't understand what's happening.
Two classes are involved : Salle and Ville. Here's the Hibernate XML files : Salle.hbm.xml & Ville.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 2 f?vr. 2017 11:28:16 by Hibernate Tools 4.3.5.Final -->
<hibernate-mapping>
<class name="metier.Salle" table="salle" catalog="aevbadherents" optimistic-lock="version">
<id name="idSalle" type="int">
<column name="idSALLE" />
<generator class="assigned" />
</id>
<many-to-one name="ville" class="metier.Ville" fetch="select">
<column name="idVilleSalle" />
</many-to-one>
<property name="adresse1" type="string">
<column name="Adresse1" length="80" />
</property>
<property name="adresse2" type="string">
<column name="Adresse2" length="80" />
</property>
<property name="description" type="string">
<column name="Description" length="500" />
</property>
<set name="courses" table="cours" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdSalle" not-null="true" />
</key>
<one-to-many class="metier.Cours" />
</set>
<set name="passagegrades" table="passagegrade" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdSalle" />
</key>
<one-to-many class="metier.Passagegrade" />
</set>
</class>
</hibernate-mapping>
The second file :
<hibernate-mapping>
<class name="metier.Ville" table="ville" catalog="aevbadherents" optimistic-lock="version">
<id name="idVille" type="int">
<column name="idVILLE" />
<generator class="assigned" />
</id>
<many-to-one name="departement" class="metier.Departement" fetch="select">
<column name="idDepartement" not-null="true" />
</many-to-one>
<property name="nom" type="string">
<column name="Nom" length="60" not-null="true" />
</property>
<property name="codepostal" type="string">
<column name="codepostal" length="6" not-null="true" />
</property>
<property name="gpslat" type="string">
<column name="GPSLat" length="12" not-null="true" />
</property>
<property name="gpslon" type="string">
<column name="GPSLon" length="12" not-null="true" />
</property>
<set name="adherentsForIdVilleResid" table="adherent" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdVilleResid" />
</key>
<one-to-many class="metier.Adherent" />
</set>
<set name="clubs" table="club" inverse="true" lazy="true" fetch="select">
<key>
<column name="idville" not-null="true" />
</key>
<one-to-many class="metier.Club" />
</set>
<set name="salles" table="salle" inverse="true" lazy="true" fetch="select">
<key>
<column name="idVilleSalle" />
</key>
<one-to-many class="metier.Salle" />
</set>
<set name="adherentsForIdVilleNais" table="adherent" inverse="true" lazy="true" fetch="select">
<key>
<column name="IdVilleNais" />
</key>
<one-to-many class="metier.Adherent" />
</set>
</class>
</hibernate-mapping>
I read that this exception may be caused by a JAR conflict, but I did not find anything.I don't use Maven (maybe I should ?), so let me show you the JARs included :
antlr-2.7.7.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.2-javadoc.jar
commons-logging-1.2.jar
dom4j-1.6.1.jar
freemarker-2.3.19.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.11.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
log4j-1.2.15.jar
mysql-connector-java-5.1.40-bin.jar
ognl-3.0.6.jar
struts2-core-2.3.15.3.jar
truc.txt
xwork-core-2.3.15.3.jar
Please help me, as I'm stumped...
One of the possible cause for this problem is that you have in your classpath several versions of the same class.
I have been looking in java2s.com and, none of the jar you listed, seems to contain the class javassist.util.proxy.Proxy, so I will try to find if any other jar contains that class using jarscan with the following command:
jarscan -d PATH_TO_YOUR_CLASSPATH_DIR -j javassist.util.proxy.Proxy
You can download jarscan from here https://java.net/projects/jarscan/downloads
If you found that several packages contains the same class, you are done.
Malaguna,
Thanks for your help. Here's the result of jarscan :
D:\temp\java\jarscan>jarscan -j javassist.util.proxy.Proxy
......................
+javassist-3.18.1-GA.jar
javassist-3.18.1-GA.jar\javassist/util/proxy/Proxy.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$1.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$2.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$3.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$ClassLoaderProvide
r.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$Find2MethodsArgs.c
lass
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$ProxyDetails.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory$UniqueName.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyFactory.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObject.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObjectInputStream.class
javassist-3.18.1-GA.jar\javassist/util/proxy/ProxyObjectOutputStream.class
----------------------------------------------
Scanned archives: 22
Errors: 0
Archives with hits: 12
So, it means that no other jar contains that class.
I get the following exception when I have my open JPA entity mapping set up with a one-to-many mapping listed after a one-to-one mapping. When I switch the order, I don't get the exception.
I'm assuming that there is an XSD rule being applied, but what is the purpose of that rule?
Failed to execute goal
org.apache.openjpa:openjpa-maven-plugin:2.2.2:enhance (enhancer) on
project: Execution enhancer of goal
org.apache.openjpa:openjpa-maven-plugin:2.2.2:enhance failed:
org.xml.sax.SAXException: Invalid content was found starting with
element 'one-to-many'. One of
'{"http://java.sun.com/xml/ns/persistence/orm":one-to-one,
"http://java.sun.com/xml/ns/persistence/orm":many-to-many,
"http://java.sun.com/xml/ns/persistence/orm":element-collection,
"http://java.sun.com/xml/ns/persistence/orm":embedded,
"http://java.sun.com/xml/ns/persistence/orm":transient}' is expected.
<!-- FAILED -->
<entity class="com.test.comm">
<table schema="dbo" name="tbl_comm_data"/>
<attributes>
<id name="commId">
<column name="comm_id"/>
</id>
<basic name="commName">
<column name="comm_name"/>
</basic>
<one-to-one name="CommType" target-entity="com.test.TblCommType" mapped-by="TblComm" fetch="LAZY">
<cascade>
<cascade-merge/>
</cascade>
</one-to-one>
<one-to-many name="CommDtls" target-entity="com.test.TblCommDtl" mapped-by="tblCommFreq">
<cascade>
<cascade-merge/>
</cascade>
</one-to-many>
</attributes>
</entity>
<!-- WORKED -->
<entity class="com.test.comm">
<table schema="dbo" name="tbl_comm_data"/>
<attributes>
<id name="commId">
<column name="comm_id"/>
</id>
<basic name="commName">
<column name="comm_name"/>
</basic>
<one-to-many name="CommDtls" target-entity="com.test.TblCommDtl" mapped-by="tblCommFreq">
<cascade>
<cascade-merge/>
</cascade>
</one-to-many>
<one-to-one name="CommType" target-entity="com.test.TblCommType" mapped-by="TblComm" fetch="LAZY">
<cascade>
<cascade-merge/>
</cascade>
</one-to-one>
</attributes>
</entity>
A little snippet of a database schema I'm trying to define in my "schema.xml" file:
<table name="hotelroom" phpName="hotelroom">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="room_number" type="varchar" size="10" required="true" />
<column name="price" type="numeric" defaultValue="1000" required="true" />
<unique>
<unique-column name="room_number" />
</unique>
</table>
In PostgreSQL for that "price" column I would've written CHECK (price > 0::numeric),but I can't seem to find any way to achieve this here.I've checked the documentation (http://propelorm.org/documentation/reference/schema.html), but couldn't find anything on this.
Thank you for the time.
You're using v1, but from the doc link above, looks like you're using v2,
I think you're looking for the GreaterThan which is only available from v2 onwards.
<behavior name="validate">
<parameter name="rule1" value="{column: price, validator: GreaterThan, options: {value: 0, message=Price is not valid}}" />
</behavior>