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]









share|improve this question




















  • 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















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]









share|improve this question




















  • 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













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]









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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














  • 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








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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?