Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:40:15+00:00 2026-06-12T09:40:15+00:00

I have a Simple insert and update test for a table: case class Player(id:

  • 0

I have a Simple insert and update test for a table:

    case class Player(id: UUID, name: String, email: String)

with all the appropriate setup in a model object for performing inserts and finds.

Running the following test:

class PlayerSpec extends Specification {
  "Player" should {

    val application = FakeApplication(additionalConfiguration =  inMemoryDatabase("test"))

    "insert a player" in {
      running(application) {

        val uuid = UUID.randomUUID()

        Player.insert(Player(uuid, "Joe Person", "joe.player@someplace.mail")) must beEqualTo(1)
      }
    }

    "Find a player by id" in {
      running(application) {
        val uuid = UUID.randomUUID()

        Player.insert(Player(uuid, "Jane Person", "jane.player@someplace.mail"))

        Player.findById(uuid) must beEqualTo(Some(Player(uuid, "Jane Person", "jane.player@someplace.mail")))
      }
    }

  }
}

I get a green bar in Intellij (both examples pass). However, when I run this in the play console I get the following error:

[info] PlayerSpec
[info] 
[info] Player should
[info] + insert a player
[error] ! Find a player by id
[error]     anon$1: Configuration error [Cannot connect to database [default]] Configuration.scala:258)
 ....

Is this a configuration issue, or am I missing some sort of a beforeEach type call?

EDIT

Just adding the db code, for more reference

case class Player(id: UUID, name: String, email: String)

object Player {

  private val fullPlayer = {
    get[UUID]("player.id")(Utils.rowToUuid) ~
    get[String]("player.name") ~
    get[String]("player.email") map {
      case id~name~email => Player(id, name, email)
    }
  }

  def insert(player: Player) = {
    DB.withConnection { implicit c =>

      SQL(
        """
          insert into player (id, name, email) values (
             {id}, {name}, {email}
          )
        """
      ).on(
        'id -> player.id.toString,
        'name -> player.name,
        'email -> player.email
      ).executeUpdate()

    }
  }

  def findById(id: UUID) : Option[Player] = {
    DB.withConnection { implicit c =>
      SQL("select * from player where id = {id}").on('id -> id).as(fullPlayer.singleOpt)
    }
  }
}

rowToUUID:

object Utils {
  implicit def rowToUuid: Column[UUID] = Column.nonNull {
    (value, meta) =>
      val MetaDataItem(qualified, nullable, clazz) = meta
      value match {
        case uuid: UUID => Right(uuid)
        case _ => Left(TypeDoesNotMatch("Cannot convert " + value + ":" + value.asInstanceOf[AnyRef].getClass + " to UUID for column " + qualified))
      }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:40:18+00:00Added an answer on June 12, 2026 at 9:40 am

    You should not reuse a FakeApplication for multiple tests.

    Just change

     val application = FakeApplication(additionalConfiguration =  inMemoryDatabase("test"))
    

    to

    def application() = FakeApplication(additionalConfiguration =  inMemoryDatabase("test"))
    

    To produce a new FakeApplication each time you call application.
    It would be good style to call this function with parenthesis.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a simple Table per Type Entity Framework 4.0 model :- ALl classes
I have a simple test, where I am trying to update the object, but
I have simple SSIS package which reads data from flat file and insert into
I have a method which does a simple mysql insert, when I tried to
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple class with width and height member fields which define number of
I have simple database - one table with 6 collumns. 3 of them i
I have created an extremely simple junit test, which creates a null product in
I'm trying to make simple many-to-one association, using NHibernate.. I have class Recruit with
I have isolated a problem we are running into down to a simple test:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.