FAQ
Should Cayenne copy/clone mutable objects, such as Date?

For example, if I modify a date after setting it in a Cayenne object
(person), it modifies the value stored by Cayenne:

   SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
   Date d1 = timeFormat.parse("2014-02-01");
   person.setStartDate(d1);
   d1.setYear(2013 - 1900); // Date hackery
   System.out.println("Start Date = " + person.getStartDate());

This outputs:

Start Date = Fri Feb 01 00:00:00 EST 2013

I've never actually experienced an issue with Cayenne not copying a
Date/etc, but was wondering your thoughts on this.

Thanks,

mrg

Search Discussions

  • John Huss at Sep 6, 2014 at 10:55 pm
    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" wrote:

    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
  • Michael Gentry at Sep 7, 2014 at 1:15 am
    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" wrote:

    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
  • John Huss at Sep 8, 2014 at 1:17 am
    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" wrote:

    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
  • Andrus Adamchik at Sep 8, 2014 at 6:42 am
    Also Java 8 Date and Time if Java 8 is an option:

    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html

    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" wrote:

    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
  • Aristedes Maniatis at Sep 8, 2014 at 7:40 am
    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:

    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html

    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" wrote:

    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Michael Gentry at Sep 8, 2014 at 12:55 pm
    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

       byte[] data = { 1, 2, 3, 4 };
       person.setData(data);
       data[0] = 5;
       for (int i = 0; i < person.getData().length; i++)
           System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg

    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis wrote:

    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:

    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" wrote:

    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Mike Kienenberger at Sep 8, 2014 at 12:59 pm
    I think it would be difficult to enforce, even if we wanted to
    disallow it, since any non-primitive could be mutable.

    What I might do is to change my templates so that certain types, like
    Date and byte[], are automatically cloned in the setter methods,
    though.

    On Mon, Sep 8, 2014 at 8:54 AM, Michael Gentry wrote:
    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

    byte[] data = { 1, 2, 3, 4 };
    person.setData(data);
    data[0] = 5;
    for (int i = 0; i < person.getData().length; i++)
    System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg

    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis wrote:

    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:

    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Hugi Thordarson at Sep 8, 2014 at 1:03 pm
    That won't help with mutable types, since modifying them will not use the setter method.

    - hugi


    On 8.9.2014, at 12:58, Mike Kienenberger wrote:

    I think it would be difficult to enforce, even if we wanted to
    disallow it, since any non-primitive could be mutable.

    What I might do is to change my templates so that certain types, like
    Date and byte[], are automatically cloned in the setter methods,
    though.

    On Mon, Sep 8, 2014 at 8:54 AM, Michael Gentry wrote:
    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

    byte[] data = { 1, 2, 3, 4 };
    person.setData(data);
    data[0] = 5;
    for (int i = 0; i < person.getData().length; i++)
    System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg

    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis wrote:

    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:

    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Mike Kienenberger at Sep 8, 2014 at 1:07 pm
    Sure it will.


    Object myMutableType = x;

    entity.setType(myMutableType); // makes a copy of myMutableType with x value

    myMutableType.changeTo(y);

    (entity still has a copy that points to x rather than y)


    On Mon, Sep 8, 2014 at 9:02 AM, Hugi Thordarson wrote:
    That won't help with mutable types, since modifying them will not use the setter method.

    - hugi


    On 8.9.2014, at 12:58, Mike Kienenberger wrote:

    I think it would be difficult to enforce, even if we wanted to
    disallow it, since any non-primitive could be mutable.

    What I might do is to change my templates so that certain types, like
    Date and byte[], are automatically cloned in the setter methods,
    though.

    On Mon, Sep 8, 2014 at 8:54 AM, Michael Gentry wrote:
    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

    byte[] data = { 1, 2, 3, 4 };
    person.setData(data);
    data[0] = 5;
    for (int i = 0; i < person.getData().length; i++)
    System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg

    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis wrote:

    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:

    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • John Huss at Sep 8, 2014 at 2:20 pm
    The answer is to use immutable data types. Unfortunately that takes some
    work in Java. Anyway, it's not that difficult to write a Cayenne
    ExtendedType subclass to allow using custom attribute types that are
    immutable, if you can find or create an immutable data type that fits your
    needs. For byte[] you could use ImmutableList in guava:

    http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableList.html


    On Mon, Sep 8, 2014 at 7:54 AM, Michael Gentry wrote:

    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

    byte[] data = { 1, 2, 3, 4 };
    person.setData(data);
    data[0] = 5;
    for (int i = 0; i < person.getData().length; i++)
    System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg

    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis wrote:

    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:
    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" wrote:

    Is that a realistic option?

    On Sat, Sep 6, 2014 at 6:55 PM, John Huss wrote:

    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne
    object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Michael Gentry at Sep 8, 2014 at 2:31 pm
    I was thinking in CDO's writeProperty() we could test if a date or array
    and clone them if true. Otherwise, just advertise that we don't clone
    mutable values as a limitation of the framework. I suspect for most use
    cases this is a reasonable limitation.

    On Mon, Sep 8, 2014 at 10:20 AM, John Huss wrote:

    The answer is to use immutable data types. Unfortunately that takes some
    work in Java. Anyway, it's not that difficult to write a Cayenne
    ExtendedType subclass to allow using custom attribute types that are
    immutable, if you can find or create an immutable data type that fits your
    needs. For byte[] you could use ImmutableList in guava:


    http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableList.html


    On Mon, Sep 8, 2014 at 7:54 AM, Michael Gentry wrote:

    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

    byte[] data = { 1, 2, 3, 4 };
    person.setData(data);
    data[0] = 5;
    for (int i = 0; i < person.getData().length; i++)
    System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg


    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis <ari@maniatis.org>
    wrote:
    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:
    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Is that a realistic option?


    On Sat, Sep 6, 2014 at 6:55 PM, John Huss <johnthuss@gmail.com>
    wrote:
    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne
    object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat
    ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not
    copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
  • Tony Giaccone at Sep 8, 2014 at 5:08 pm
    Mike,

    This "problem" is not unique to Cayenne. it's the nature of Java. Anytime you hold on to a reference to a mutable value and other objects have references to that object any change in one reference is reflected in all references. If you don't understand that java behavior your life is going to be painful. I don't think this is a Cayenne problem as much as a Java problem.

    Tony
    On Sep 8, 2014, at 10:30 AM, Michael Gentry wrote:

    I was thinking in CDO's writeProperty() we could test if a date or array
    and clone them if true. Otherwise, just advertise that we don't clone
    mutable values as a limitation of the framework. I suspect for most use
    cases this is a reasonable limitation.

    On Mon, Sep 8, 2014 at 10:20 AM, John Huss wrote:

    The answer is to use immutable data types. Unfortunately that takes some
    work in Java. Anyway, it's not that difficult to write a Cayenne
    ExtendedType subclass to allow using custom attribute types that are
    immutable, if you can find or create an immutable data type that fits your
    needs. For byte[] you could use ImmutableList in guava:


    http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/ImmutableList.html



    On Mon, Sep 8, 2014 at 7:54 AM, Michael Gentry <mgentry@masslight.net>
    wrote:
    I think everyone is getting wrapped up around Dates. My general question
    was about mutable types.

    byte[] data = { 1, 2, 3, 4 };
    person.setData(data);
    data[0] = 5;
    for (int i = 0; i < person.getData().length; i++)
    System.out.println("Data[" + i + "] = " + person.getData()[i]);

    Data[0] = 5

    Data[1] = 2

    Data[2] = 3

    Data[3] = 4

    Again, modifying the original value changes what is stored internally by
    Cayenne.

    Thanks,

    mrg


    On Mon, Sep 8, 2014 at 3:39 AM, Aristedes Maniatis <ari@maniatis.org>
    wrote:
    And https://github.com/ThreeTen/threetenbp for Java 6/7 users.

    Ari

    On 8/09/2014 4:42pm, Andrus Adamchik wrote:
    Also Java 8 Date and Time if Java 8 is an option:
    http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html
    Andrus
    On Sep 8, 2014, at 4:17 AM, John Huss wrote:

    Sure, use Joda time.
    On Sep 6, 2014 8:15 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Is that a realistic option?


    On Sat, Sep 6, 2014 at 6:55 PM, John Huss <johnthuss@gmail.com>
    wrote:
    My thoughts are: don't use Date.
    On Sep 6, 2014 4:58 PM, "Michael Gentry" <mgentry@masslight.net>
    wrote:
    Should Cayenne copy/clone mutable objects, such as Date?

    For example, if I modify a date after setting it in a Cayenne
    object
    (person), it modifies the value stored by Cayenne:

    SimpleDateFormat timeFormat = new SimpleDateFormat
    ("yyyy-MM-dd");
    Date d1 = timeFormat.parse("2014-02-01");
    person.setStartDate(d1);
    d1.setYear(2013 - 1900); // Date hackery
    System.out.println("Start Date = " + person.getStartDate());

    This outputs:

    Start Date = Fri Feb 01 00:00:00 EST 2013

    I've never actually experienced an issue with Cayenne not
    copying a
    Date/etc, but was wondering your thoughts on this.

    Thanks,

    mrg
    --
    -------------------------->
    Aristedes Maniatis
    GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriescayenne
postedSep 6, '14 at 9:58p
activeSep 8, '14 at 5:08p
posts13
users7
websitecayenne.apache.org

People

Translate

site design / logo © 2021 Grokbase