Hibernate mapping internal class, Error “Could not determine type for: timeStamps”












0















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









share|improve this question

























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
















0















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









share|improve this question

























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














0












0








0








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















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












2 Answers
2






active

oldest

votes


















1














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






share|improve this answer































    1














    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
    }





    share|improve this answer


























    • 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











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














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






    share|improve this answer




























      1














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






      share|improve this answer


























        1












        1








        1







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






        share|improve this answer













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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 29 '18 at 14:07









        John CamerinJohn Camerin

        385111




        385111

























            1














            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
            }





            share|improve this answer


























            • 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
















            1














            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
            }





            share|improve this answer


























            • 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














            1












            1








            1







            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
            }





            share|improve this answer















            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
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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



















            • 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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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

            Monofisismo

            compose and upload a new article using a custom form

            How to correct the classpath of spring boot application so that it contains a single, compatible version of...