problem with many-to-many and postgres

9 views
Skip to first unread message

Tim Pigden

unread,
Apr 9, 2013, 10:27:04 AM4/9/13
to mapp...@googlegroups.com
Hi
I'm getting a problem with many-to-many on creating new objects.

Essentially the many-to-many table update is failing because the initial "parent" record is not present when it gets to write the link table.

I'm having to use this pattern to circumvent it:

  def partSave(trip: Trip): Validated[Trip] = {
      val savedActivities = trip.activities
      // logger.debug(s"partSave trip: trip" + trip.id)
      val trip2 = trip.copy(activities = Set.empty)
      for {
        trip3 <- MapperD.create(tripDao, trip2)  // saves the record without the associated set of things
        trip5 <- MapperD.update(tripDao, trip3, trip) // updates the record with the things back 
      } yield trip5

    }

Oddly it was working then stopped. And in another table with the same pattern it was working fine then stopped. Is the order in which the data is written nondeterministic perhaps?

Can you give me a hint as to best logging to turn on to get a better explanation of the problem?

  object TripEntity extends Entity[String, NaturalStringId, Trip] {
    override val databaseSchema = DefaultPersist.schema

    val id = key("id") to (_.id)
    val solution_id = column("solution_id") to (_.solutionId)
    val name = column("name") to (_.name)
    val resourceSet = manytoone(ResourceSetEntity) to (_.resourceSet)
    val activities = manytomany(ActivityEntity) join("trip_activities", "trip_id", "activity_id") to (_.activities)

    def constructor(implicit m: ValuesMap) = new Trip(id,
      name,
      resourceSet,
      activities
    ) with NaturalStringId

  }


Tim

Konstantinos Kougios

unread,
Apr 9, 2013, 10:30:53 AM4/9/13
to mapp...@googlegroups.com
Is there any cyclic dependency between
TripEntity,ResourceSetEntity,ActivityEntity? I.e. ResourceSetEntity
referencing ActivityEntity or TripEntity?

Can you share all entities? And also all mapperdao log output (the inserts)?
> --
> You received this message because you are subscribed to the Google
> Groups "mapperdao" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to mapperdao+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Tim Pigden

unread,
Apr 9, 2013, 10:38:20 AM4/9/13
to mapp...@googlegroups.com
will take a while - there's about 12 entities involved directly and indirectly. But definitiely no cyclic dependencies. But it's not a tree (both activity and trip point to resourceset.
I'll email you directly rather than through group.


To unsubscribe from this group and stop receiving emails from it, send an email to mapperdao+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "mapperdao" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapperdao+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.





--
Tim Pigden
Optrak Distribution Software Limited
+44 (0)1992 517100
http://www.linkedin.com/in/timpigden
http://optrak.com
Optrak Distribution Software Ltd is a limited company registered in England and Wales.
Company Registration No. 2327613 Registered Offices: Orland House, Mead Lane, Hertford, SG13 7AT England 
This email and any attachments to it may be confidential and are intended solely for the use of the individual to whom it is addressed. Any views or opinions expressed are solely those of the author and do not necessarily represent those of Optrak Distribution Software Ltd. If you are not the intended recipient of this email, you must neither take any action based upon its contents, nor copy or show it to anyone. Please contact the sender if you believe you have received this email in error.
Reply all
Reply to author
Forward
0 new messages