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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:57:15+00:00 2026-06-07T01:57:15+00:00

I’m working in a WebSocket server with user authentication. I don’t really now how

  • 0

I’m working in a WebSocket server with user authentication. I don’t really now how to store this user among request. My WebSocket connection will probably stay open for hours and sometimes it will receive 100 request per minute and sometimes just 2 per hours (it’s unpredictable). The user data may be changed by another application, this is not my question but it may be relevant. I’m using spring 3 and hibernate 3.6.9.

My question is : Should I use a specific transaction management and how do I manage these user data.

I’ve test 2 use case :

1.
Load my user entity at log in and merge() it in each request. I have to merge it because transaction are closed after each request. Merge is not a good solution because it do not load the database entity but persist the one merged. So if the data where update somewhere else it’ll revert them and not load the updated one.

2.
At log in I only store the user ID and I find() my user at each request. To avoid database request flood I’ve set a second level cache but according to my sql server log hibernate still run a request per find().

Here is some concrete code and configuration :

persistence.xml

<persistence-unit name="greenpacs">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
    <property name="hibernate.archive.autodetection" value="class"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>

    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/db"/>
    <property name="hibernate.connection.user" value="root"/>
    <property name="hibernate.connection.password" value="password"/>
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>

applicationContext.xml

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="greenpacs" />
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

User entity

@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class User {
@Id
@Column(name = "userId", unique = true, nullable = false)
private Integer id;

private String pwd;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "User_Role", joinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "userId") }, inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") })
private List<Role> roles;

@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name="id")
private Person person;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.user", cascade = CascadeType.ALL)
private List<Pacs> pacs;

// getter&setter

WebSocket Listener

@Component
public class UserManager implements WampMessageHandler {

UserService userService;
//Autowired setter

    User user;

@Override
public void onConnected(WampConnection connection) {
       //loginmethod return userId
       user = userService.find(userId);
    }

@Transactional
@Override
public boolean onMessage(String sessionId, int messageType, Object[] msg)
        throws BadMessageFormException {
    user = userService.merge(user);  
            //or  
            user = userService.find(user.getId());  
            ...
}

My UserService just redirect to EntityManager’s methods.

  • 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-07T01:57:17+00:00Added an answer on June 7, 2026 at 1:57 am

    Your second solution looks like the obvious one. You’re seeing a query to the database because you didn’t set the hibernate.cache.use_second_level_cache property to true.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string

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.