JHipster is not creating the table DatcatAttributeMetadata to the database. This is a child table with a foreign key relationship manyToOne with parent table DatcatAttributeMetadata.
Parent table was created earlier but when adding DatcatAttributeMetadata using Jhipster entity module this table is not being added to PostgresSql and throwing an error ERROR: relation "datcat_attribute_metadata" does not exist
Have tried --force-entity and mvn liquidbase:diff multiple times but still the table is not being created in DB
Below is the code snippet to
master.xml
20170612191949_added_entity_constraints_DatcatAttributeMetadata.xml
20170612191949_added_entity_DatcatAttributeMetadata.xml
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20170612161115_added_entity_DatcatDatasetMetadata.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20170612191949_added_entity_DatcatAttributeMetadata.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->
<include file="classpath:config/liquibase/changelog/20170612191949_added_entity_constraints_DatcatAttributeMetadata.xml" relativeToChangelogFile="false"/>
<!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
<?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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<!--
Added the constraints for entity DatcatAttributeMetadata.
-->
<changeSet id="20170612191949-2" author="jhipster">
<addForeignKeyConstraint baseColumnNames="dataset_id_id"
baseTableName="datcat_attribute_metadata"
constraintName="fk_datcat_attribute_metadata_dataset_id_id"
referencedColumnNames="dataset_id"
referencedTableName="datcat_dataset_metadata"/>
</changeSet>
</databaseChangeLog>
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="now" value="now()" dbms="h2"/>
<property name="now" value="current_timestamp" dbms="postgresql"/>
<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql"/>
<changeSet id="20170612191949-1" author="jhipster">
<createTable tableName="datcat_attribute_metadata">
<column name="attribute_id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="attribute_def" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="primary_key" type="boolean">
<constraints nullable="false" />
</column>
<column name="foreign_key" type="varchar(255)">
<constraints nullable="true" />
</column>
<column name="attribute_datatype" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="attribute_lenght" type="integer">
<constraints nullable="true" />
</column>
<column name="dataset_id_id" type="bigint">
<constraints nullable="false" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>
</changeSet>
Logs
2017-06-12 16:15:01.198 DEBUG 44521 --- [ XNIO-2 task-3] c.e.p.d.apis.aop.logging.LoggingAspect : Enter: com.exelon.predix.datacatalog.apis.web.rest.DatcatAttributeMetadataResource.getAllDatcatAttributeMetadata() with argument[s] = [Page request [number: 0, size 20, sort: id: ASC]]
2017-06-12 16:15:01.207 DEBUG 44521 --- [ XNIO-2 task-3] .d.a.w.r.DatcatAttributeMetadataResource : REST request to get a page of DatcatAttributeMetadata
2017-06-12 16:15:01.210 DEBUG 44521 --- [ XNIO-2 task-3] c.e.p.d.apis.aop.logging.LoggingAspect : Enter: com.exelon.predix.datacatalog.apis.service.DatcatAttributeMetadataService.findAll() with argument[s] = [Page request [number: 0, size 20, sort: id: ASC]]
2017-06-12 16:15:01.210 DEBUG 44521 --- [ XNIO-2 task-3] a.s.i.DatcatAttributeMetadataServiceImpl : Request to get all DatcatAttributeMetadata
Hibernate: select datcatattr0_.attribute_id as attribut1_0_, datcatattr0_.attribute_datatype as attribut2_0_, datcatattr0_.attribute_def as attribut3_0_, datcatattr0_.attribute_lenght as attribut4_0_, datcatattr0_.dataset_id_dataset_id as dataset_7_0_, datcatattr0_.foreign_key as foreign_5_0_, datcatattr0_.primary_key as primary_6_0_ from datcat_attribute_metadata datcatattr0_ order by datcatattr0_.attribute_id asc limit ?
2017-06-12 16:15:01.223 WARN 44521 --- [ XNIO-2 task-3] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 42P01
2017-06-12 16:15:01.223 ERROR 44521 --- [ XNIO-2 task-3] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: relation "datcat_attribute_metadata" does not exist
Position: 331
2017-06-12 16:15:01.237 ERROR 44521 --- [ XNIO-2 task-3] c.e.p.d.apis.aop.logging.LoggingAspect : Exception in com.exelon.predix.datacatalog.apis.service.DatcatAttributeMetadataService.findAll() with cause = 'org.hibernate.exception.SQLGrammarException: could not extract ResultSet' and exception = 'could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet'
Please not I have updated the column names of the primary key in both parent and child table as dataset_id and attribute_id respectively by making changes in liquidbase file and using #Column annotation in domain class.
Related
After introducing a custom UserType, I write a simple Entity class along with its Repository and a unit test class to test the UserType.
Here is the entity class:
#Entity
#Table(name = "person")
#TypeDef(name = "JsonDataUserType", typeClass = JsonDataUserType.class)
public class Person {
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
private String firstName;
private String lastName;
#Type(type = "JsonDataUserType")
private Map<String, String> additionalData;
...
}
}
And I create a new table person in the database.
Based on the JHipster Creating an entity document, I create a databaseChangeLog XML file with a name of time sequence
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
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
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="now" value="now()" dbms="h2"/>
<property name="now" value="current_timestamp" dbms="postgresql"/>
<property name="floatType" value="float4" dbms="postgresql, h2"/>
<property name="floatType" value="float" dbms="mysql, oracle, mssql"/>
<changeSet id="20180508041900-1" author="jhipster">
<createTable tableName="person">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="varchar(80)">
<constraints nullable="false" />
</column>
<column name="last_name" type="varchar(80)">
<constraints nullable="true" />
</column>
<column name="additional_data" type="jsonb">
<constraints nullable="false" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove-->
The testes (gradlew test) fail. An error stack is something as the followings:
java.lang.IllegalStateException
Caused by: org.springframework.beans.factory.BeanCreationException
Caused by: javax.persistence.PersistenceException
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException
When I run the individual test, I get
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [person]
...
What is missing?
Am newbie to Liferay. I have created one JSF portlet and added the service builder to it. Using this link Generate a Persistence Framework. After configure a service builder i have generated the source using service builder. But am getting following exception when build service of project.
Exception in thread "main" java.lang.IllegalArgumentException: No entity column exist with column database name guestbookId for entity Guestbook
[echo] at com.liferay.portal.tools.service.builder.ServiceBuilder._getEntityColumnByColumnDBName(ServiceBuilder.java:4242)
[echo] at com.liferay.portal.tools.service.builder.ServiceBuilder._getColumnLengths(ServiceBuilder.java:3857)
[echo] at com.liferay.portal.tools.service.builder.ServiceBuilder._createSQLIndexes(ServiceBuilder.java:3355)
[echo] at com.liferay.portal.tools.service.builder.ServiceBuilder.<init>(ServiceBuilder.java:796)
[echo] at com.liferay.portal.tools.service.builder.ServiceBuilder.main(ServiceBuilder.java:216)
[echo] -Dservice.tpl.spring_xml_session=com/liferay/portal/tools/service/builder/dependencies/spring_xml_session.ftl
[echo] Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
[mkdir] Created dir: D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-classes
[copy] Copied 9 empty directories to 9 empty directories under D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-classes
[javac] Compiling 38 source files to D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-classes
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[jar] Building jar: D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\lib\jsfguestbook-portlet-service.jar
[delete] Deleting directory D:\liferay\liferay-plugins-sdk-7.0\portlets\jsfguestbook-portlet\docroot\WEB-INF\service-classes
BUILD SUCCESSFUL
Total time: 8 seconds
Also after built the service i have added the code as per article. I got no method is configured for following code.
public Guestbook getFirstGuestbookByName(long groupId, String name) throws SystemException {
Guestbook guestbook = null;
List<Guestbook> guestbooks = guestbookPersistence.findByName(groupId, name); // This method is not exist.
if (guestbooks != null && guestbooks.size() > 0) {
guestbook = guestbooks.get(0);
}
return guestbook;
}
My service.xml configuration is follows
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd">
<service-builder package-path="com.liferay.docs.guestbook">
<author>muthuvignesh.k</author>
<namespace>GB</namespace>
<entity name="Guestbook" local-service="true" uuid="true">
<!-- PK fields -->
<column name="guestbookId" type="long" primary="true"></column>
<!-- Group instance -->
<column name="groupId" type="long"></column>
<!-- Audit fields -->
<column name="companyId" type="long"></column>
<column name="userId" type="long"></column>
<column name="userName" type="String"></column>
<column name="createDate" type="Date"></column>
<column name="modifiedDate" type="Date"></column>
<column name="name" type="String"></column>
<finder name="GroupId" return-type="Collection">
<finder-column name="groupId"></finder-column>
</finder>
</entity>
<entity name="Entry" local-service="true" uuid="true">
<!-- PK fields -->
<column name="entryId" type="long" primary="true"></column>
<!-- Group instance -->
<column name="groupId" type="long"></column>
<!-- Audit fields -->
<column name="companyId" type="long"></column>
<column name="userId" type="long"></column>
<column name="userName" type="String"></column>
<column name="createDate" type="Date"></column>
<column name="modifiedDate" type="Date"></column>
<column name="name" type="String"></column>
<column name="email" type="String"></column>
<column name="message" type="String"></column>
<column name="guestbookId" type="long"></column>
<finder name="G_G" return-type="Collection">
<finder-column name="groupId"></finder-column>
<finder-column name="guestbookId"></finder-column>
</finder>
</entity>
<exceptions>
<exception>GuestbookName</exception>
<exception>EntryName</exception>
<exception>EntryMessage</exception>
<exception>EntryEmail</exception>
</exceptions>
Since i have using Liferay 7.0 for this. How to overcome this.
I had a same error in 6.2. It seems that the error was in the WEB-INF/sql/indexes.sql file. An index entry was using the field that the service builder could not find (but existed in the service.xml).
I think (but I couldn't verify it) the problem was occurred by an older version of liferay maven plugin (6.2.0-ga1). By deleting the file and upgrading to version 6.2.5, service builder generated a different indexes.sql and the build was successful.
Service Builder
The issue appears to be in your service builder.
1.What stands out the most is your malformed XML. You need to close the tag.
2.Secondly in your Java code you are trying to access a finder that doesn't exist. The only finder you have defined in your hibernate file is groupId. It would look something like
return guestbookPersistence.findByGroupId(groupId);
3.To create a groupid and name find it would look similar to your entry finder.
<finder name="G_N" return-type="Collection">
<finder-column name="groupId"></finder-column>
<finder-column name="name"></finder-column>
</finder>
and your java code
return guestbookPersistence.findByG_N(groupId, name);
service.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_7_0_0.dtd">
<service-builder package-path="com.latham.data">
<author>muthuvignesh.k</author>
<namespace>GB</namespace>
<entity name="Guestbook" local-service="true" uuid="true">
<!-- PK fields -->
<column name="guestbookId" type="long" primary="true"></column>
<!-- Group instance -->
<column name="groupId" type="long"></column>
<!-- Audit fields -->
<column name="companyId" type="long"></column>
<column name="userId" type="long"></column>
<column name="userName" type="String"></column>
<column name="createDate" type="Date"></column>
<column name="modifiedDate" type="Date"></column>
<column name="name" type="String"></column>
<finder name="GroupId" return-type="Collection">
<finder-column name="groupId"></finder-column>
</finder>
<finder name="G_N" return-type="Collection">
<finder-column name="groupId"></finder-column>
<finder-column name="name"></finder-column>
</finder>
</entity>
<entity name="Entry" local-service="true" uuid="true">
<!-- PK fields -->
<column name="entryId" type="long" primary="true"></column>
<!-- Group instance -->
<column name="groupId" type="long"></column>
<!-- Audit fields -->
<column name="companyId" type="long"></column>
<column name="userId" type="long"></column>
<column name="userName" type="String"></column>
<column name="createDate" type="Date"></column>
<column name="modifiedDate" type="Date"></column>
<column name="name" type="String"></column>
<column name="email" type="String"></column>
<column name="message" type="String"></column>
<column name="guestbookId" type="long"></column>
<finder name="G_G" return-type="Collection">
<finder-column name="groupId"></finder-column>
<finder-column name="guestbookId"></finder-column>
</finder>
</entity>
<exceptions>
<exception>GuestbookName</exception>
<exception>EntryName</exception>
<exception>EntryMessage</exception>
<exception>EntryEmail</exception>
</exceptions>
</service-builder>
The tutorial you linked to is for Liferay 6.2 but your document definition is for Liferay 7. There were some very big changes between 6.2 and 7. Your code seems to be compatible with both however you should still keep that in mind.
I have created custom entity employee. Now I want to add listeners for this entity so that I can track add/edit/delete employee operations.
In Liferay for portal enitites like Blogs, Group, User etc we can add properties like
value.object.listener.com.liferay.portal.model.Group=com.smb.test.hook.listeners.GroupListener
in portal.properties via hook-plugin.
But for custom entity this approach does not seem to work.
Any help would be appreciated.
For custom entity, we need to add the listener property in service-ext.properties instead of the portal.properties file.
For my employee entity I have added following property in service-ext.properties file:
value.object.listener.com.smb.employee.model.Employee=com.smb.employee.hook.listeners.EmployeeListener
Note: We need to manually create service-ext.properties file in src folder besides the service.properties file. We could have updated service.properties but since it auto-generates our changes would be lost and hence service-ext.properties is the correct liferay approach.
Here is the location of the service-ext.properties file:
Here is my service.xml:
<service-builder package-path="com.smb.employee">
<author>Suyash</author>
<namespace>smb</namespace>
<entity name="Employee" local-service="true" remote-service="true">
<!-- PK fields -->
<column name="fooId" type="long" primary="true" />
<!-- Audit fields -->
<column name="companyId" type="long" />
<column name="userId" type="long" />
<column name="userName" type="String" />
<column name="createDate" type="Date" />
<column name="modifiedDate" type="Date" />
<!-- Other fields -->
<column name="field1" type="String" />
<column name="field2" type="boolean" />
<column name="field3" type="int" />
<column name="field4" type="Date" />
<column name="field5" type="String" />
<!-- Order -->
<order by="asc">
<order-column name="field1" />
</order>
<!-- Finder methods -->
<finder name="Field2" return-type="Collection">
<finder-column name="field2" />
</finder>
</entity>
</entity>
</service-builder>
I am using NLog to log error messages into csv:
<target name="csv" xsi:type="File"
fileName="${basedir}/Logs/log.csv"
archiveFileName="${basedir}/Logs/Archives/log.{#####}.csv"
archiveAboveSize="10240"
archiveNumbering="Sequence"
concurrentWrites="true"
keepFileOpen="false">
<layout xsi:type="CSVLayout" delimiter="Comma" withHeader="false">
<column name="time" layout="${longdate}" />
<column name="message" layout="${message}" />
<column name="logger" layout="${logger}"/>
<column name="level" layout="${level}"/>
</layout>
</target>
How can I add a column to track the code line number?
Thank you.
Try to add ${callsite} layout renderer.
<column name="source" layout="${callsite:fileName=true}" />
I have what strikes me as a very unusual behavior from Linq for NHibernate.
In general, all my entity classes are working just fine, but one of them throws a "NonUniqueResult" exception from the NHibernate namespace under the following condition.
If I call the following:
getSession<MyClass>().Linq<MyClass>().Count();
it throws the exception. If I call
getSession<MyClass>().Linq<MyClass>().ToList().Count();
it does not.
There's no problem with the other CRUD operations for this class, so I don't think it's my mappings.
My guess is that it has something to do with how the Count() operator ultimately gets materialized as a SQL query, but beyond that I'm not sure where to look.
Updated to include mapping of the class in question
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="My.App.MyClass, My.App" table="MyClass">
<id name="Id" access="property" column="Id" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid.comb">
</generator>
</id>
<version name="TimeStamp" access="property" column="TimeStamp" type="Int32" />
<property name="CreatedOn" access="property" type="System.DateTime">
<column name="CreatedOn"/>
</property>
<property name="Ticker" access="property" type="Int32">
<column name="Ticker"/>
</property>
<property name="DifferentTicker" access="property" type="Int32">
<column name="DifferentTicker"/>
</property>
<property name="SomeDecimal" access="property" type="System.Decimal">
<column name="SomeDecimal"/>
</property>
<property name="StillAnotherTicker" access="property" type="Int32">
<column name="StillAnotherTicker"/>
</property>
<property name="IsActive" access="property" type="Boolean">
<column name="IsActive"/>
</property>
<many-to-one name="RelatedThing" access="property" class="My.App.RelatedThing, My.App" column="RelatedThingId" lazy="proxy" />
<many-to-one name="OtherRelatedThing" access="property" class="My.App.OtherRelatedThing, My.App" column="OtherRelatedThingId" lazy="proxy" />
<bag name="_schedule" access="property" table="Schedule" lazy="false" cascade="all-delete-orphan">
<key column="MyClassId" />
<one-to-many class="My.App.Schedule, My.App" />
</bag>
<bag name="Vectors" access="property" table="Vectors" lazy="false">
<key column="MyClassId" />
<many-to-many class="My.App.Channels.BaseVector, My.App" column="vectorid"/>
</bag>
</class>
</hibernate-mapping>
Both version work fine for me in a simple unit test. In this example:
using ( var tx = Session.BeginTransaction() )
{
int count = Session.Linq<Customer>().Count();
Assert.Equal( 2, count );
count = Session.Linq<Customer>().ToList().Count();
Assert.Equal( 2, count );
tx.Commit();
}
The first query performs a SQL count:
NHibernate: SELECT count(*) as y0_ FROM "Customer" this_
And the second gets all returns all items into a temporary list and then calls Count() on the list:
NHibernate: SELECT this_.Id as Id9_0_, this_.Name as Name9_0_ FROM "Customer" this_
This leads me to believe that there might be an issue with your mappings. And you really want to get the first one working cause the second won't scale for large datasets.