Closed flrndttrch closed 8 years ago
It look like you have a problem getting the all VehicleGroup's.
com.bosch.iot.reliance.truckmonitoring.web.rest.VehicleGroupResource.getAllVehicleGroups(VehicleGroupResource.java:88) ~[classes/:na]
Hi andidev, thanks for your reply. I recreated the vehicleGroup and I dont get the error anymore. However now I get the same one with the TelematicsDataResource instead. Could it be that the order of my entities in the master.xml is not correct? If yes what do I have to consider when I am reordering?
So what I want to do is the follwoing: Truck (1) <-----> (1) TelematicsUnit (1) <----> (*) TelematicsData
My master.xml looks like this now:
<include file="classpath:config/liquibase/changelog/20151015111316_added_entity_VehicleGroup.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20151015115604_added_entity_TelematicsUnit.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20151015115749_added_entity_TelematicsData.xml" relativeToChangelogFile="false"/>
<include file="classpath:config/liquibase/changelog/20151015074035_added_entity_Truck.xml" relativeToChangelogFile="false"/>
and additionally here is the telematicsData.json
{
"relationships": [
{
"relationshipId": 1,
"relationshipName": "telematicsUnit",
"otherEntityName": "telematicsUnit",
"relationshipType": "many-to-one",
"otherEntityField": "serialNumber"
}
],
"fields": [
{
"fieldId": 1,
"fieldName": "commandCode",
"fieldType": "String"
},
{
"fieldId": 2,
"fieldName": "messageType",
"fieldType": "String"
},
{
"fieldId": 3,
"fieldName": "gpsTime",
"fieldType": "DateTime"
},
{
"fieldId": 4,
"fieldName": "gpsFix",
"fieldType": "String"
},
{
"fieldId": 5,
"fieldName": "latitude",
"fieldType": "Float"
},
{
"fieldId": 6,
"fieldName": "longitude",
"fieldType": "Float"
},
{
"fieldId": 7,
"fieldName": "speed",
"fieldType": "Float"
},
{
"fieldId": 8,
"fieldName": "heading",
"fieldType": "Float"
},
{
"fieldId": 9,
"fieldName": "numSatellites",
"fieldType": "Integer"
},
{
"fieldId": 10,
"fieldName": "gsmLac",
"fieldType": "String"
},
{
"fieldId": 11,
"fieldName": "gsmCellId",
"fieldType": "String"
},
{
"fieldId": 12,
"fieldName": "gsmSignalPower",
"fieldType": "Float"
},
{
"fieldId": 13,
"fieldName": "batVoltage",
"fieldType": "Float"
},
{
"fieldId": 14,
"fieldName": "batState",
"fieldType": "BatteryState",
"fieldValues": "Low,Medium,High"
},
{
"fieldId": 15,
"fieldName": "chargerStatus",
"fieldType": "Integer"
},
{
"fieldId": 16,
"fieldName": "mainsVoltage",
"fieldType": "Float"
},
{
"fieldId": 17,
"fieldName": "mainsPowerState",
"fieldType": "Boolean"
},
{
"fieldId": 18,
"fieldName": "tamperState",
"fieldType": "Boolean"
},
{
"fieldId": 19,
"fieldName": "ignitionState",
"fieldType": "Boolean"
},
{
"fieldId": 20,
"fieldName": "gpi2State",
"fieldType": "Boolean"
},
{
"fieldId": 21,
"fieldName": "gpo1Status",
"fieldType": "Boolean"
},
{
"fieldId": 22,
"fieldName": "gpo2Status",
"fieldType": "Boolean"
},
{
"fieldId": 23,
"fieldName": "packetId",
"fieldType": "Integer"
},
{
"fieldId": 24,
"fieldName": "smsResponseStatus",
"fieldType": "Integer"
},
{
"fieldId": 25,
"fieldName": "firmwareVersion",
"fieldType": "LocalDate"
}
],
"changelogDate": "20151015115749",
"dto": "no",
"pagination": "no"
}
I might have found the root of the issue. The error I am getting now is "org.postgresql.util.PSQLException: ERROR: column telematics0_.telematicsunit_id does not exist" I think the problem is, that it expects telematicsunit_id and not telematics_unit_id which is written in the liquibase changelog. So as soon as a change the column via the pgAdmin to telematicsunit_id it seems to work. So now I am going to verify if not using camel case in the entity creation solves my issue.
Yes that is a bit strange.
I wonder if this maybe is a spring data bug.
Could you post how your @Query
annotation looks like in com.bosch.iot.reliance.truckmonitoring.repository.VehicleGroupResource.findAllWithEagerRelationships()
also please post the VehicleGroup.json
and `VehicleGroup.java``(the entity) files as well.
VehicleGroupResource.findAllWithEagerRelationships()
produces the following SQL
select distinct
vehiclegro0_.id as id1_15_0_,
truck2_.id as id1_14_1_,
vehiclegro0_.color_hex as color_he2_15_0_,
vehiclegro0_.name as name3_15_0_,
truck2_.assigned as assigned2_14_1_,
truck2_.license_plate as license_3_14_1_,
truck2_.status as status4_14_1_,
truck2_.telematicsUnit_id as telemati5_14_1_,
truck2_.vendor_id as vendor_i6_14_1_,
trucks1_.vehicle_groups_id as vehicle_1_15_0__,
trucks1_.trucks_id as trucks_i2_16_0__
from VEHICLE_GROUP vehiclegro0_
left outer join VEHICLE_GROUP_TRUCK trucks1_ on vehiclegro0_.id=trucks1_.vehicle_groups_id
left outer join TRUCK truck2_ on trucks1_.trucks_id=truck2_.id
where telematicsUnit_id
is for some reason camel cased instead of underscored as you say.
The VehicleGroupRepository looks just like this:
public interface VehicleGroupRepository extends JpaRepository<VehicleGroup,Long> {
}
and in the VehicleGroupResource is no @Query Annotation. Where do I have to look for this?
{
"relationships": [
{
"relationshipId": 1,
"relationshipName": "truck",
"otherEntityName": "truck",
"relationshipType": "many-to-many",
"ownerSide": false,
"otherEntityRelationshipName": "vehicleGroup"
}
],
"fields": [
{
"fieldId": 1,
"fieldName": "name",
"fieldType": "String",
"fieldValidateRules": [
"required"
]
},
{
"fieldId": 2,
"fieldName": "colorHex",
"fieldType": "String"
}
],
"changelogDate": "20151015111316",
"dto": "no",
"pagination": "no"
}
package com.bosch.iot.reliance.truckmonitoring.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;
/**
* A VehicleGroup.
*/
@Entity
@Table(name = "VEHICLE_GROUP")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName="vehiclegroup")
public class VehicleGroup implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotNull
@Column(name = "name", nullable = false)
private String name;
@Column(name = "color_hex")
private String colorHex;
@ManyToMany(mappedBy = "vehicleGroups")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Truck> trucks = new HashSet<>();
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 getColorHex() {
return colorHex;
}
public void setColorHex(String colorHex) {
this.colorHex = colorHex;
}
public Set<Truck> getTrucks() {
return trucks;
}
public void setTrucks(Set<Truck> trucks) {
this.trucks = trucks;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
VehicleGroup vehicleGroup = (VehicleGroup) o;
if ( ! Objects.equals(id, vehicleGroup.id)) return false;
return true;
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public String toString() {
return "VehicleGroup{" +
"id=" + id +
", name='" + name + "'" +
", colorHex='" + colorHex + "'" +
'}';
}
}
So this is the VehicleGroup, but like I said, there are no more problems with the VehicleGroup. The problems are mainly with the TelematicsUnit and TelematicsData.
Yes, your right. Though it is to hard to investigate this without the ability to generate the code.
Could you provide the generated project in a github repo? or at least all json files needed to reproduce this error.
@justDoGit it definitely looks like you got an issue, but it's really complicated for us to find why it is if we don't have your full configuration. As one-to-one relationships are not widely used, I guess there is a side-effect with them, but it's hard to tell. I understand you can't share all your source code publicly (I see the package name...), so maybe we could do this in private? My email is in the form firstname.lastname@gmail.com
@justDoGit by the way, I've worked quite a lot in the IoT field recently (as part of my real job, I've just spent 4 month on an IoT system for the automotive industry, exactly like you...), and I wouldn't use Hibernate collections to store telematics data (or even trucks, if you have lots of them). This is why we have the Cassandra option -> Cassandra is great for storing telematics data, you should definitely consider it
i can confirm this issue, i get similar issue when running tests with one-to-one entities
Caused by: org.hibernate.HibernateException: Missing column: testa_id in SAMPLEGRADLE.PUBLIC.TEST_B
at org.hibernate.mapping.Table.validateColumns(Table.java:366)
at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1338)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:175)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:525)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 61 more
I think the probelm is with the naming resolution of the id column, we use SpringNamingStrategy but still somehow hibernate is using a different pattern, not sure if spring bug or hibernate bug
As the PR is merged I'm closing this
Hi guys
I am facing the same issue with a one-to-one relationship. Is there any fix that you are aware of?
Thanks
It's fixed on master in #2690 and #2695
Thanks @cbornet
Looking forward to update to the next release then! :)
Hello, I just tried to create a one-to-one relationship between two entities. After I created them the applications started up, but as soon as I try to create this entity I get the following error:
Here are the JSON files of the entities:
TelematicsUnit
Truck
Did I miss something or is this a problem of jHipster? Thanks a lot for the help