User Login

Please enter user name and password into following boxes!

If you are not registered yet, please click

Forget Password

If you forget your password, please click

hibernate

  • MappedBy in bi-directional @ManyToMany : what is the reason

    Question: 1. What is the reason for setting MappedBy in bidirectional many-to-many relationships? 2. When one table has significant amount of records, while other has a few, which side is better to put mappedBy Answer: It's actually a good question, and it helps to understand the concept of an "owning" entity. If you want to prevent both sides (in a bidirectional relationship) from having join tables, a good idea, then you need to have a mappedBy= element on one side. Whether or not there is a join table is controlled by the mappedBy="name" el...Continue Reading

    JUnit 4 Testing with DBUnit in Spring Hibernate Application

    HsqlDb Connection 1. Download hsqldb.zip file from here 2. Extract zip file 3. Open bin folder in the hsqldb folder 4. Edit runServer.bat file as follows: cd ..\data @java -classpath ../lib/hsqldb.jar org.hsqldb.server.Server -database.0 mem:sample -dbname.0 sample 5. Save and run runServer.bat file 6. After running this file you should see the command prompt as follows: Spring applicationContext-test.xml File <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"...Continue Reading

    Spring MVC JUnit And Mockito Configuration

    @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/applicationContext.xml", "classpath:/mvc-dispatcher-servlet.xml", "classpath:/spring-security.xml"}) @WebAppConfiguration public class GumrukServiceUtilTest { @Autowired WebApplicationContext wac; @Autowired private UserService userService; private MockMvc mockMvc; @Before public void setup(){ MockitoAnnotations.initMocks(this); this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();...Continue Reading

    Hibernate Password Encryption with Jasypt in Spring MVC

    Create Password After downloaded Jasypt CLI Tools, execute following code by using encrypt.sh for linux based OS, or encrypt.bat file for Windows located in bin folder: encrypt.bat input="secret" password=encryptorpassword algorithm=PBEWithMD5AndTripleDES Output looks like this: AdK2HjMDfxTABg9ZP3kXSWsKo3t4rSn7 Note: Whenever run above command in command prompt, you will get different password each time because PBEWithMD5AndTripleDES algorithm and many other algorithms use random salt generator. For more information please click Add Maven Depe...Continue Reading

    Hibernate Search Enable Logging

    First of all, we should set log4j.logger.org.hibernate=TRACE property in log4j.properties file, then enable Apache Lucene indexwriter.infostream property as follows: <prop key="hibernate.search.default.indexwriter.infostream">true</prop> Note that we should'nt use this property in runtime because of performance degredation....Continue Reading

    Hibernate Many to Many Relationship to Save only Association in Join Table

    If we want to save or update only association table, we shouldn't use cascade in @JoinTable annotation. UserGroup Table @Entity public class UserGroup { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int userGroupId; @Size(min = 4, max = 20, groups = SizeConstraintGroup.class) @Column(length = 20) private String name; @ManyToMany(fetch = FetchType.LAZY) @JsonIgnore @JoinTable( name = "UserGroup_User", joinColumns = @JoinColumn(name = "userGroupId", nullable = false, updatable...Continue Reading

    Hibernate ManyToMany Save, SaveOrUpdate And Delete Operations

    In Hibernate ManyToMany relationship, save or saveOrUpdate operations must be as follows: User Entity @ManyToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL) @JoinTable( name = "UserRole_User", joinColumns = @JoinColumn(name = "userId", nullable = false, updatable = false), inverseJoinColumns = @JoinColumn(name = "userRoleId", nullable = false, updatable = false) ) private List userRoleList=new ArrayList(); In Line 1, cascade provides that when user is saved, an insert operation will be executed on UserRol...Continue Reading

    Spring, Hibernate, Ehcache, C3P0 And Hibernate Search Configuration

    <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan" value="com.codesenior.telif.local.model"/> <property name="hibernateProperties"> <props>