Spring JPA data repository not acting like it should
I am new to Spring
and I am trying to create an Object
and add it to my database and then get the value from it. As far as I understand I should not add any extra lines and findAll
should return me a proper looking String
as a result.
But the result I get looks like this:
[model.Orders@4a163575, model.Orders@7ecec90d]
What I also understood is that I should not add get/set
methods to Spring
as they should be automatically generated, but when I try to cast the model.Orders@4a163575
into an Object
and do the get
method It tells me that there is no get
method.
So here is my Object
:
@Data
@Entity
public class Orders
public Orders(String orderName)
this.orderName = orderName;
public Orders()
@Id
@GeneratedValue
private Long id;
private String orderName;
Then the findAll
method:
@Repository
public class OrderDao
public List<Orders> findAll()
return em.createQuery("select p from Orders p", Orders.class).getResultList();
And where I launch it all:
public static void main(String args)
ConfigurableApplicationContext ctx =
new AnnotationConfigApplicationContext(DbConfig.class);
OrderDao dao = ctx.getBean(OrderDao.class);
dao.save(new Orders("order1"));
dao.save(new Orders("order2"));
System.out.println(dao.findAll());
From what I have I think that the @Data
annotation is not working properly since there is no toString
nor getters/setter
.
I import the @Data
annotation with this line : import lombok.Data;
.
What am I doing wrong here.
java spring object jpa
add a comment |
I am new to Spring
and I am trying to create an Object
and add it to my database and then get the value from it. As far as I understand I should not add any extra lines and findAll
should return me a proper looking String
as a result.
But the result I get looks like this:
[model.Orders@4a163575, model.Orders@7ecec90d]
What I also understood is that I should not add get/set
methods to Spring
as they should be automatically generated, but when I try to cast the model.Orders@4a163575
into an Object
and do the get
method It tells me that there is no get
method.
So here is my Object
:
@Data
@Entity
public class Orders
public Orders(String orderName)
this.orderName = orderName;
public Orders()
@Id
@GeneratedValue
private Long id;
private String orderName;
Then the findAll
method:
@Repository
public class OrderDao
public List<Orders> findAll()
return em.createQuery("select p from Orders p", Orders.class).getResultList();
And where I launch it all:
public static void main(String args)
ConfigurableApplicationContext ctx =
new AnnotationConfigApplicationContext(DbConfig.class);
OrderDao dao = ctx.getBean(OrderDao.class);
dao.save(new Orders("order1"));
dao.save(new Orders("order2"));
System.out.println(dao.findAll());
From what I have I think that the @Data
annotation is not working properly since there is no toString
nor getters/setter
.
I import the @Data
annotation with this line : import lombok.Data;
.
What am I doing wrong here.
java spring object jpa
add a comment |
I am new to Spring
and I am trying to create an Object
and add it to my database and then get the value from it. As far as I understand I should not add any extra lines and findAll
should return me a proper looking String
as a result.
But the result I get looks like this:
[model.Orders@4a163575, model.Orders@7ecec90d]
What I also understood is that I should not add get/set
methods to Spring
as they should be automatically generated, but when I try to cast the model.Orders@4a163575
into an Object
and do the get
method It tells me that there is no get
method.
So here is my Object
:
@Data
@Entity
public class Orders
public Orders(String orderName)
this.orderName = orderName;
public Orders()
@Id
@GeneratedValue
private Long id;
private String orderName;
Then the findAll
method:
@Repository
public class OrderDao
public List<Orders> findAll()
return em.createQuery("select p from Orders p", Orders.class).getResultList();
And where I launch it all:
public static void main(String args)
ConfigurableApplicationContext ctx =
new AnnotationConfigApplicationContext(DbConfig.class);
OrderDao dao = ctx.getBean(OrderDao.class);
dao.save(new Orders("order1"));
dao.save(new Orders("order2"));
System.out.println(dao.findAll());
From what I have I think that the @Data
annotation is not working properly since there is no toString
nor getters/setter
.
I import the @Data
annotation with this line : import lombok.Data;
.
What am I doing wrong here.
java spring object jpa
I am new to Spring
and I am trying to create an Object
and add it to my database and then get the value from it. As far as I understand I should not add any extra lines and findAll
should return me a proper looking String
as a result.
But the result I get looks like this:
[model.Orders@4a163575, model.Orders@7ecec90d]
What I also understood is that I should not add get/set
methods to Spring
as they should be automatically generated, but when I try to cast the model.Orders@4a163575
into an Object
and do the get
method It tells me that there is no get
method.
So here is my Object
:
@Data
@Entity
public class Orders
public Orders(String orderName)
this.orderName = orderName;
public Orders()
@Id
@GeneratedValue
private Long id;
private String orderName;
Then the findAll
method:
@Repository
public class OrderDao
public List<Orders> findAll()
return em.createQuery("select p from Orders p", Orders.class).getResultList();
And where I launch it all:
public static void main(String args)
ConfigurableApplicationContext ctx =
new AnnotationConfigApplicationContext(DbConfig.class);
OrderDao dao = ctx.getBean(OrderDao.class);
dao.save(new Orders("order1"));
dao.save(new Orders("order2"));
System.out.println(dao.findAll());
From what I have I think that the @Data
annotation is not working properly since there is no toString
nor getters/setter
.
I import the @Data
annotation with this line : import lombok.Data;
.
What am I doing wrong here.
java spring object jpa
java spring object jpa
edited Nov 14 '18 at 0:16
Kolka Tankari
asked Nov 13 '18 at 23:58
Kolka TankariKolka Tankari
225
225
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You need to install lombok plugin for that it will be possible generating them
You can refer to this article how to install lombok in IntellijIdea:
Lombok annotations do not compile under Intellij idea
Please also add enable annotation processing
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
add a comment |
Well it seems I had forgotten to enable annotation processing
.
Picture to show where and how I did it
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
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%2f53291221%2fspring-jpa-data-repository-not-acting-like-it-should%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to install lombok plugin for that it will be possible generating them
You can refer to this article how to install lombok in IntellijIdea:
Lombok annotations do not compile under Intellij idea
Please also add enable annotation processing
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
add a comment |
You need to install lombok plugin for that it will be possible generating them
You can refer to this article how to install lombok in IntellijIdea:
Lombok annotations do not compile under Intellij idea
Please also add enable annotation processing
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
add a comment |
You need to install lombok plugin for that it will be possible generating them
You can refer to this article how to install lombok in IntellijIdea:
Lombok annotations do not compile under Intellij idea
Please also add enable annotation processing
You need to install lombok plugin for that it will be possible generating them
You can refer to this article how to install lombok in IntellijIdea:
Lombok annotations do not compile under Intellij idea
Please also add enable annotation processing
edited Nov 14 '18 at 0:34
answered Nov 14 '18 at 0:19
Mykhailo MoskuraMykhailo Moskura
868213
868213
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
add a comment |
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
I have it installed by following this : link
– Kolka Tankari
Nov 14 '18 at 0:22
add a comment |
Well it seems I had forgotten to enable annotation processing
.
Picture to show where and how I did it
add a comment |
Well it seems I had forgotten to enable annotation processing
.
Picture to show where and how I did it
add a comment |
Well it seems I had forgotten to enable annotation processing
.
Picture to show where and how I did it
Well it seems I had forgotten to enable annotation processing
.
Picture to show where and how I did it
answered Nov 14 '18 at 0:25
Kolka TankariKolka Tankari
225
225
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53291221%2fspring-jpa-data-repository-not-acting-like-it-should%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