Using the subselect hibernate annotation with entity
up vote
1
down vote
favorite
I want to create a view from two tables using annotions in java/JEE ,
so after some researches i found that the only way to do it is using @Subselect
annotation so I created 3 entities
the test entity
@Table
@Entity
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String nom;
@Column
private String prenom;
@Column
private int age;
@Column
private String adresse;
@Column
private Date dateNaissance;
// getters and setters
}
The compte entity
@Entity
public class Compte {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String description;
// getters and setters
}
and the entity Compte_Test wich has the same role as a view
@Entity
@Subselect("SELECT c2.id as idTest,c1.id as id,c1.solde as solde,c1.numero as numero, c2.nom as nom, c2.prenom as prenom FROM Compte c1 INNER JOIN Test c2 ON c1.id_test= c2.id")
@Synchronize({ "compte", "test" })
public class Compte_Test {
@Id
private long idCompte_Test;
@Column
private long idTest;
@Column
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String nom;
@Column
private String prenom;
// getters and setters
}
I'am using spring data @Query annotaion to get data from Compte_Test entity
@Query(value = "SELECT c from Compte_Test c ")
List<Compte_Test> fullTextSearch(Pageable pageable);
The problem is that it generates for me an error
org.postgresql.util.PSQLException: ERROR: column compte_tes0_.id_compte_test does not exist
Position : 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]
java hibernate spring-boot jpa spring-data-jpa
add a comment |
up vote
1
down vote
favorite
I want to create a view from two tables using annotions in java/JEE ,
so after some researches i found that the only way to do it is using @Subselect
annotation so I created 3 entities
the test entity
@Table
@Entity
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String nom;
@Column
private String prenom;
@Column
private int age;
@Column
private String adresse;
@Column
private Date dateNaissance;
// getters and setters
}
The compte entity
@Entity
public class Compte {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String description;
// getters and setters
}
and the entity Compte_Test wich has the same role as a view
@Entity
@Subselect("SELECT c2.id as idTest,c1.id as id,c1.solde as solde,c1.numero as numero, c2.nom as nom, c2.prenom as prenom FROM Compte c1 INNER JOIN Test c2 ON c1.id_test= c2.id")
@Synchronize({ "compte", "test" })
public class Compte_Test {
@Id
private long idCompte_Test;
@Column
private long idTest;
@Column
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String nom;
@Column
private String prenom;
// getters and setters
}
I'am using spring data @Query annotaion to get data from Compte_Test entity
@Query(value = "SELECT c from Compte_Test c ")
List<Compte_Test> fullTextSearch(Pageable pageable);
The problem is that it generates for me an error
org.postgresql.util.PSQLException: ERROR: column compte_tes0_.id_compte_test does not exist
Position : 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]
java hibernate spring-boot jpa spring-data-jpa
1
have you checked the database for the column? Is it exactly as query expects? The nameidCompte_Test
is a bit unusual name and Hibernate by default seems to prefix capital-camel-case with_
also so this miight be the problem.
– pirho
Nov 12 at 16:32
thanks @pirho for your time, I have changed the name of the id whithout the underscore but that changed nothing
– Wassim Makni
Nov 13 at 7:49
Ok but what is the field in db? is it exactlyid_compte_test
?
– pirho
Nov 13 at 7:58
the table isn't even created in the db
– Wassim Makni
Nov 13 at 8:01
Well, that is a bigger problem then. About the subselect, do you think you could achieve the same result by other means, like my answer to this quiestion suggests?
– pirho
Nov 13 at 9:16
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to create a view from two tables using annotions in java/JEE ,
so after some researches i found that the only way to do it is using @Subselect
annotation so I created 3 entities
the test entity
@Table
@Entity
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String nom;
@Column
private String prenom;
@Column
private int age;
@Column
private String adresse;
@Column
private Date dateNaissance;
// getters and setters
}
The compte entity
@Entity
public class Compte {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String description;
// getters and setters
}
and the entity Compte_Test wich has the same role as a view
@Entity
@Subselect("SELECT c2.id as idTest,c1.id as id,c1.solde as solde,c1.numero as numero, c2.nom as nom, c2.prenom as prenom FROM Compte c1 INNER JOIN Test c2 ON c1.id_test= c2.id")
@Synchronize({ "compte", "test" })
public class Compte_Test {
@Id
private long idCompte_Test;
@Column
private long idTest;
@Column
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String nom;
@Column
private String prenom;
// getters and setters
}
I'am using spring data @Query annotaion to get data from Compte_Test entity
@Query(value = "SELECT c from Compte_Test c ")
List<Compte_Test> fullTextSearch(Pageable pageable);
The problem is that it generates for me an error
org.postgresql.util.PSQLException: ERROR: column compte_tes0_.id_compte_test does not exist
Position : 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]
java hibernate spring-boot jpa spring-data-jpa
I want to create a view from two tables using annotions in java/JEE ,
so after some researches i found that the only way to do it is using @Subselect
annotation so I created 3 entities
the test entity
@Table
@Entity
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private String nom;
@Column
private String prenom;
@Column
private int age;
@Column
private String adresse;
@Column
private Date dateNaissance;
// getters and setters
}
The compte entity
@Entity
public class Compte {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String description;
// getters and setters
}
and the entity Compte_Test wich has the same role as a view
@Entity
@Subselect("SELECT c2.id as idTest,c1.id as id,c1.solde as solde,c1.numero as numero, c2.nom as nom, c2.prenom as prenom FROM Compte c1 INNER JOIN Test c2 ON c1.id_test= c2.id")
@Synchronize({ "compte", "test" })
public class Compte_Test {
@Id
private long idCompte_Test;
@Column
private long idTest;
@Column
private long id;
@Column
private long solde;
@Column
private long numero;
@Column
private String nom;
@Column
private String prenom;
// getters and setters
}
I'am using spring data @Query annotaion to get data from Compte_Test entity
@Query(value = "SELECT c from Compte_Test c ")
List<Compte_Test> fullTextSearch(Pageable pageable);
The problem is that it generates for me an error
org.postgresql.util.PSQLException: ERROR: column compte_tes0_.id_compte_test does not exist
Position : 8
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183) ~[postgresql-42.2.5.jar:42.2.5]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5]
java hibernate spring-boot jpa spring-data-jpa
java hibernate spring-boot jpa spring-data-jpa
edited Nov 13 at 8:05
asked Nov 12 at 16:20
Wassim Makni
131113
131113
1
have you checked the database for the column? Is it exactly as query expects? The nameidCompte_Test
is a bit unusual name and Hibernate by default seems to prefix capital-camel-case with_
also so this miight be the problem.
– pirho
Nov 12 at 16:32
thanks @pirho for your time, I have changed the name of the id whithout the underscore but that changed nothing
– Wassim Makni
Nov 13 at 7:49
Ok but what is the field in db? is it exactlyid_compte_test
?
– pirho
Nov 13 at 7:58
the table isn't even created in the db
– Wassim Makni
Nov 13 at 8:01
Well, that is a bigger problem then. About the subselect, do you think you could achieve the same result by other means, like my answer to this quiestion suggests?
– pirho
Nov 13 at 9:16
add a comment |
1
have you checked the database for the column? Is it exactly as query expects? The nameidCompte_Test
is a bit unusual name and Hibernate by default seems to prefix capital-camel-case with_
also so this miight be the problem.
– pirho
Nov 12 at 16:32
thanks @pirho for your time, I have changed the name of the id whithout the underscore but that changed nothing
– Wassim Makni
Nov 13 at 7:49
Ok but what is the field in db? is it exactlyid_compte_test
?
– pirho
Nov 13 at 7:58
the table isn't even created in the db
– Wassim Makni
Nov 13 at 8:01
Well, that is a bigger problem then. About the subselect, do you think you could achieve the same result by other means, like my answer to this quiestion suggests?
– pirho
Nov 13 at 9:16
1
1
have you checked the database for the column? Is it exactly as query expects? The name
idCompte_Test
is a bit unusual name and Hibernate by default seems to prefix capital-camel-case with _
also so this miight be the problem.– pirho
Nov 12 at 16:32
have you checked the database for the column? Is it exactly as query expects? The name
idCompte_Test
is a bit unusual name and Hibernate by default seems to prefix capital-camel-case with _
also so this miight be the problem.– pirho
Nov 12 at 16:32
thanks @pirho for your time, I have changed the name of the id whithout the underscore but that changed nothing
– Wassim Makni
Nov 13 at 7:49
thanks @pirho for your time, I have changed the name of the id whithout the underscore but that changed nothing
– Wassim Makni
Nov 13 at 7:49
Ok but what is the field in db? is it exactly
id_compte_test
?– pirho
Nov 13 at 7:58
Ok but what is the field in db? is it exactly
id_compte_test
?– pirho
Nov 13 at 7:58
the table isn't even created in the db
– Wassim Makni
Nov 13 at 8:01
the table isn't even created in the db
– Wassim Makni
Nov 13 at 8:01
Well, that is a bigger problem then. About the subselect, do you think you could achieve the same result by other means, like my answer to this quiestion suggests?
– pirho
Nov 13 at 9:16
Well, that is a bigger problem then. About the subselect, do you think you could achieve the same result by other means, like my answer to this quiestion suggests?
– pirho
Nov 13 at 9:16
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266178%2fusing-the-subselect-hibernate-annotation-with-entity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
have you checked the database for the column? Is it exactly as query expects? The name
idCompte_Test
is a bit unusual name and Hibernate by default seems to prefix capital-camel-case with_
also so this miight be the problem.– pirho
Nov 12 at 16:32
thanks @pirho for your time, I have changed the name of the id whithout the underscore but that changed nothing
– Wassim Makni
Nov 13 at 7:49
Ok but what is the field in db? is it exactly
id_compte_test
?– pirho
Nov 13 at 7:58
the table isn't even created in the db
– Wassim Makni
Nov 13 at 8:01
Well, that is a bigger problem then. About the subselect, do you think you could achieve the same result by other means, like my answer to this quiestion suggests?
– pirho
Nov 13 at 9:16