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 9172441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:20:48+00:00 2026-06-17T16:20:48+00:00

I want to store java.util.Date (or Timestamp) as an int (or Long) in my

  • 0

I want to store java.util.Date (or Timestamp) as an int (or Long) in my db using Squeryl.

I’d like to control how the date is transformed to the number and vice versa.

How can I achieve this?

I’m pretty new to scala/squeryl, coming from java/hibernate.
Back in java/hibernate I could create user types and either register them globaly or use them localy on a field with an annotation. This user type defined methods for how to persist the object type to db and how to load it from the db.

I read some of the squeryl and scala docs, noticed two things:

  1. there are custom types

  2. there is a implicit function mechanism that is called for conversions

I know one of these can help me but I didn’t find any good full examples to understand how.

Any help is appreciated!

  • 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-17T16:20:49+00:00Added an answer on June 17, 2026 at 4:20 pm

    Please see this example :

    https://github.com/max-l/squeryl-extended-field-types-example/blob/master/src/main/scala/example/MyCustomTypes.scala

    in your case, you subsitute TTimestamp for TLong (the backing JDBC type) and DateTime for Date (you might want consider using the joda date though).

    implicit val dateAsLongTEF = new NonPrimitiveJdbcMapper[Long, Date, TLong](longTEF, this) {
      def convertFromJdbc(v: Long) = new Date(v)
      def convertToJdbc(v: Date) = v.getTime
    }
    
    implicit val optionDateAsLongTEF = 
    new TypedExpressionFactory[Option[Date], TOptionLong] 
      with DeOptionizer[Long, Date, TLong, Option[Date], TOptionLong]  {
    
        val deOptionizer = dateAsLongTEF
    }
    

    Note: the fact that you use TLong and TOptionLong means that you’ll be able to
    compare a number column to a long backed column in the DSL.

    Update: there is a limitation that prevents re registering a primitive type,
    so you’ll need to have a wrapper type, I updated the example in the github project…

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

Sidebar

Related Questions

I am using a java.util.BitSet to store a dense vector of bits. I want
I want to store and retrieve images to/from database using java beans, which data
I have something like: import java.util.HashMap; import java.util.List; public class A { HashMap<Long, List<B>>
I want to create cache in java to store user sessions. It's something like
I have written my own java.util.List implementation, and now i want to store it
I'll be very simple: I want to be able to store Java objects from
I want to store values and retrieve them from a Java HashMap. This is
I want to use java key store to save keys and certificates. can anybody
I was using a properties.xml file which i stored with java.util.properties storeToXML. but storeToXML
If I was to given a specific java.util.Date, how can I generate a start

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.