Hibernate mapping internal class, Error “Could not determine type for: timeStamps”
I have Entity "Task" that needs to have an internal component called "timestamps" that holds values for when the task was submitted, started and completed.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
private Timestamps timestamps;
// getters setters
}
Then I created the Timestamps class
public class Timestamps {
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
How do I make this mapping so when I retrieve the information in JSON format I have something like this?
# task
{
"task": # ASCII string
"status": # one of "submitted", "started", "completed"
"timestamps": {
"submitted": # unix/epoch time
"started": # unix/epoch time or null if not started
"completed": # unix/epoch time or null if not completed
}
}
java json hibernate jpa
add a comment |
I have Entity "Task" that needs to have an internal component called "timestamps" that holds values for when the task was submitted, started and completed.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
private Timestamps timestamps;
// getters setters
}
Then I created the Timestamps class
public class Timestamps {
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
How do I make this mapping so when I retrieve the information in JSON format I have something like this?
# task
{
"task": # ASCII string
"status": # one of "submitted", "started", "completed"
"timestamps": {
"submitted": # unix/epoch time
"started": # unix/epoch time or null if not started
"completed": # unix/epoch time or null if not completed
}
}
java json hibernate jpa
@Spara It does not work: I got "No identifier specified for entity: com.tasks.Timestamps"
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:50
2
If you don't want to persist Timestamps in database you can use@Transient
. If you want to persits Timestamps as a relation in DB you should make it as entity with an identifier then a@ManyToOne
relation with task enitity
– Spara
Dec 29 '18 at 13:53
add a comment |
I have Entity "Task" that needs to have an internal component called "timestamps" that holds values for when the task was submitted, started and completed.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
private Timestamps timestamps;
// getters setters
}
Then I created the Timestamps class
public class Timestamps {
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
How do I make this mapping so when I retrieve the information in JSON format I have something like this?
# task
{
"task": # ASCII string
"status": # one of "submitted", "started", "completed"
"timestamps": {
"submitted": # unix/epoch time
"started": # unix/epoch time or null if not started
"completed": # unix/epoch time or null if not completed
}
}
java json hibernate jpa
I have Entity "Task" that needs to have an internal component called "timestamps" that holds values for when the task was submitted, started and completed.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
private Timestamps timestamps;
// getters setters
}
Then I created the Timestamps class
public class Timestamps {
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
How do I make this mapping so when I retrieve the information in JSON format I have something like this?
# task
{
"task": # ASCII string
"status": # one of "submitted", "started", "completed"
"timestamps": {
"submitted": # unix/epoch time
"started": # unix/epoch time or null if not started
"completed": # unix/epoch time or null if not completed
}
}
java json hibernate jpa
java json hibernate jpa
edited Dec 29 '18 at 21:19
daedsidog
1,3312827
1,3312827
asked Dec 29 '18 at 13:35
Thadeu Antonio Ferreira MeloThadeu Antonio Ferreira Melo
194213
194213
@Spara It does not work: I got "No identifier specified for entity: com.tasks.Timestamps"
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:50
2
If you don't want to persist Timestamps in database you can use@Transient
. If you want to persits Timestamps as a relation in DB you should make it as entity with an identifier then a@ManyToOne
relation with task enitity
– Spara
Dec 29 '18 at 13:53
add a comment |
@Spara It does not work: I got "No identifier specified for entity: com.tasks.Timestamps"
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:50
2
If you don't want to persist Timestamps in database you can use@Transient
. If you want to persits Timestamps as a relation in DB you should make it as entity with an identifier then a@ManyToOne
relation with task enitity
– Spara
Dec 29 '18 at 13:53
@Spara It does not work: I got "No identifier specified for entity: com.tasks.Timestamps"
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:50
@Spara It does not work: I got "No identifier specified for entity: com.tasks.Timestamps"
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:50
2
2
If you don't want to persist Timestamps in database you can use
@Transient
. If you want to persits Timestamps as a relation in DB you should make it as entity with an identifier then a @ManyToOne
relation with task enitity– Spara
Dec 29 '18 at 13:53
If you don't want to persist Timestamps in database you can use
@Transient
. If you want to persits Timestamps as a relation in DB you should make it as entity with an identifier then a @ManyToOne
relation with task enitity– Spara
Dec 29 '18 at 13:53
add a comment |
2 Answers
2
active
oldest
votes
You can put the @Embeddable annotation on Timestamps. Hibernate will map the fields as columns in the same table.
You might also need an @Embedded on the Timestamps field in Task (I cant remeber for certain if both sides need an annotation).
add a comment |
If you don't want to persist Timestamps
in DB and just use it In DTO This will helps you:
@Transient
annotation is used to indicate that a field is not to be persisted in the database.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@Transient
private Timestamps timestamps;
// getters setters
}
If you want to persist Timestamps
as a relation you should do something like this:
@Entity
public class Timestamps {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@ManyToOne
private Timestamps timestamps;
// getters setters
}
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
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%2f53970048%2fhibernate-mapping-internal-class-error-could-not-determine-type-for-timestamp%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 can put the @Embeddable annotation on Timestamps. Hibernate will map the fields as columns in the same table.
You might also need an @Embedded on the Timestamps field in Task (I cant remeber for certain if both sides need an annotation).
add a comment |
You can put the @Embeddable annotation on Timestamps. Hibernate will map the fields as columns in the same table.
You might also need an @Embedded on the Timestamps field in Task (I cant remeber for certain if both sides need an annotation).
add a comment |
You can put the @Embeddable annotation on Timestamps. Hibernate will map the fields as columns in the same table.
You might also need an @Embedded on the Timestamps field in Task (I cant remeber for certain if both sides need an annotation).
You can put the @Embeddable annotation on Timestamps. Hibernate will map the fields as columns in the same table.
You might also need an @Embedded on the Timestamps field in Task (I cant remeber for certain if both sides need an annotation).
answered Dec 29 '18 at 14:07


John CamerinJohn Camerin
385111
385111
add a comment |
add a comment |
If you don't want to persist Timestamps
in DB and just use it In DTO This will helps you:
@Transient
annotation is used to indicate that a field is not to be persisted in the database.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@Transient
private Timestamps timestamps;
// getters setters
}
If you want to persist Timestamps
as a relation you should do something like this:
@Entity
public class Timestamps {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@ManyToOne
private Timestamps timestamps;
// getters setters
}
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
add a comment |
If you don't want to persist Timestamps
in DB and just use it In DTO This will helps you:
@Transient
annotation is used to indicate that a field is not to be persisted in the database.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@Transient
private Timestamps timestamps;
// getters setters
}
If you want to persist Timestamps
as a relation you should do something like this:
@Entity
public class Timestamps {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@ManyToOne
private Timestamps timestamps;
// getters setters
}
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
add a comment |
If you don't want to persist Timestamps
in DB and just use it In DTO This will helps you:
@Transient
annotation is used to indicate that a field is not to be persisted in the database.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@Transient
private Timestamps timestamps;
// getters setters
}
If you want to persist Timestamps
as a relation you should do something like this:
@Entity
public class Timestamps {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@ManyToOne
private Timestamps timestamps;
// getters setters
}
If you don't want to persist Timestamps
in DB and just use it In DTO This will helps you:
@Transient
annotation is used to indicate that a field is not to be persisted in the database.
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@Transient
private Timestamps timestamps;
// getters setters
}
If you want to persist Timestamps
as a relation you should do something like this:
@Entity
public class Timestamps {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private Timestamp submitted;
private Timestamp started;
private Timestamp completed;
//getter and setters
}
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer Id;
private String Status;
@ManyToOne
private Timestamps timestamps;
// getters setters
}
edited Dec 29 '18 at 13:57
answered Dec 29 '18 at 13:48


SparaSpara
3,02211441
3,02211441
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
add a comment |
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
It kind of works. However, I would like to have the timestamps to persist in the database as columns of task. The annoying thing is that I need to make the JSON in that particular format.
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:53
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%2f53970048%2fhibernate-mapping-internal-class-error-could-not-determine-type-for-timestamp%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
@Spara It does not work: I got "No identifier specified for entity: com.tasks.Timestamps"
– Thadeu Antonio Ferreira Melo
Dec 29 '18 at 13:50
2
If you don't want to persist Timestamps in database you can use
@Transient
. If you want to persits Timestamps as a relation in DB you should make it as entity with an identifier then a@ManyToOne
relation with task enitity– Spara
Dec 29 '18 at 13:53