diff --git a/spring-hibernate3-dao/.classpath b/spring-hibernate3-dao/.classpath new file mode 100644 index 0000000000..9c9f508af0 --- /dev/null +++ b/spring-hibernate3-dao/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-hibernate3-dao/.gitignore b/spring-hibernate3-dao/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-hibernate3-dao/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-hibernate3-dao/.project b/spring-hibernate3-dao/.project new file mode 100644 index 0000000000..8aa9e7ad58 --- /dev/null +++ b/spring-hibernate3-dao/.project @@ -0,0 +1,60 @@ + + + spring-hibernate3-dao + + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.zeroturnaround.eclipse.rebelXmlBuilder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + org.zeroturnaround.eclipse.jrebelNature + + diff --git a/spring-hibernate3-dao/.settings/.jsdtscope b/spring-hibernate3-dao/.settings/.jsdtscope new file mode 100644 index 0000000000..b46b9207a8 --- /dev/null +++ b/spring-hibernate3-dao/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/spring-hibernate3-dao/.settings/org.eclipse.jdt.core.prefs b/spring-hibernate3-dao/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..62492222ad --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/spring-hibernate3-dao/.settings/org.eclipse.jdt.ui.prefs b/spring-hibernate3-dao/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..471e9b0d81 --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,55 @@ +#Sat Jan 21 23:04:06 EET 2012 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=true +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=true +sp_cleanup.correct_indentation=true +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=true +sp_cleanup.make_local_variable_final=true +sp_cleanup.make_parameters_final=true +sp_cleanup.make_private_fields_final=false +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=true +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=false +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=true +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=true +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=true +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/spring-hibernate3-dao/.settings/org.eclipse.m2e.core.prefs b/spring-hibernate3-dao/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000000..f897a7f1cb --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/spring-hibernate3-dao/.settings/org.eclipse.m2e.wtp.prefs b/spring-hibernate3-dao/.settings/org.eclipse.m2e.wtp.prefs new file mode 100644 index 0000000000..ef86089622 --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.m2e.wtp.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false diff --git a/spring-hibernate3-dao/.settings/org.eclipse.wst.common.component b/spring-hibernate3-dao/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000000..557fa1bf21 --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/spring-hibernate3-dao/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-hibernate3-dao/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000000..a67649dfa5 --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/spring-hibernate3-dao/.settings/org.eclipse.wst.jsdt.ui.superType.container b/spring-hibernate3-dao/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000000..3bd5d0a480 --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/spring-hibernate3-dao/.settings/org.eclipse.wst.jsdt.ui.superType.name b/spring-hibernate3-dao/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000000..05bd71b6ec --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/spring-hibernate3-dao/.settings/org.eclipse.wst.validation.prefs b/spring-hibernate3-dao/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000000..cacf5451ae --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,14 @@ +DELEGATES_PREFERENCE=delegateValidatorList +USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; +USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; +USER_PREFERENCE=overrideGlobalPreferencestruedisableAllValidationfalseversion1.2.303.v201202090300 +eclipse.preferences.version=1 +override=true +suspend=false +vals/org.eclipse.jst.jsf.ui.JSFAppConfigValidator/global=FF01 +vals/org.eclipse.jst.jsp.core.JSPBatchValidator/global=FF01 +vals/org.eclipse.jst.jsp.core.JSPContentValidator/global=FF01 +vals/org.eclipse.jst.jsp.core.TLDValidator/global=FF01 +vals/org.eclipse.wst.dtd.core.dtdDTDValidator/global=FF01 +vals/org.eclipse.wst.jsdt.web.core.JsBatchValidator/global=TF02 +vf.version=3 diff --git a/spring-hibernate3-dao/.settings/org.eclipse.wst.ws.service.policy.prefs b/spring-hibernate3-dao/.settings/org.eclipse.wst.ws.service.policy.prefs new file mode 100644 index 0000000000..9cfcabe16f --- /dev/null +++ b/spring-hibernate3-dao/.settings/org.eclipse.wst.ws.service.policy.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/spring-hibernate3-dao/.springBeans b/spring-hibernate3-dao/.springBeans new file mode 100644 index 0000000000..7623a7e888 --- /dev/null +++ b/spring-hibernate3-dao/.springBeans @@ -0,0 +1,14 @@ + + + 1 + + + + + + + src/main/webapp/WEB-INF/mvc-servlet.xml + + + + diff --git a/spring-hibernate3-dao/README.md b/spring-hibernate3-dao/README.md new file mode 100644 index 0000000000..afb2185d60 --- /dev/null +++ b/spring-hibernate3-dao/README.md @@ -0,0 +1,3 @@ +Spring MVC with Java Configuration +========= + diff --git a/spring-hibernate3-dao/pom.xml b/spring-hibernate3-dao/pom.xml new file mode 100644 index 0000000000..8458cd7b72 --- /dev/null +++ b/spring-hibernate3-dao/pom.xml @@ -0,0 +1,152 @@ + + 4.0.0 + org.baeldung + spring-hibernate3-dao + 0.1-SNAPSHOT + + spring-hibernate3-dao + war + + + + + + + org.springframework + spring-web + ${org.springframework.version} + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework + spring-context + ${org.springframework.version} + + + + + + org.hibernate + hibernate-core + 3.6.10.Final + + + mysql + mysql-connector-java + 5.1.25 + runtime + + + + + + com.google.guava + guava + 14.0.1 + + + + + + junit + junit-dep + ${junit.version} + test + + + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + + spring-hibernate3-dao + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + + + + + + + org.codehaus.cargo + cargo-maven2-plugin + + true + + jetty8x + embedded + + + + + + + 8082 + + + + + + + + + + + + 3.2.2.RELEASE + + + 1.7.5 + 1.0.11 + + + 1.3 + 4.11 + 1.9.5 + + 4.2.4 + 4.2.4 + + 1.8.0 + 1.8.9 + + + + \ No newline at end of file diff --git a/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java new file mode 100644 index 0000000000..13922658a6 --- /dev/null +++ b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/config/PersistenceConfig.java @@ -0,0 +1,77 @@ +package org.baeldung.spring.persistence.config; + +import java.util.Properties; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.hibernate3.HibernateTransactionManager; +import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.google.common.base.Preconditions; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-mysql.properties" }) +@ComponentScan({ "org.baeldung.spring.persistence.dao", "org.baeldung.spring.persistence.service" }) +public class PersistenceConfig { + + @Autowired + private Environment env; + + public PersistenceConfig() { + super(); + } + + @Bean + public AnnotationSessionFactoryBean sessionFactory() { + final AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean(); + sessionFactory.setDataSource(restDataSource()); + sessionFactory.setPackagesToScan(new String[] { "org.baeldung.spring.persistence.model" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource restDataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public HibernateTransactionManager transactionManager() { + final HibernateTransactionManager txManager = new HibernateTransactionManager(); + txManager.setSessionFactory(sessionFactory().getObject()); + + return txManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties hibernateProperties() { + return new Properties() { + { + setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + // setProperty("hibernate.globally_quoted_identifiers", "true"); + // note: necessary in launchpad-storage, but causing problems here + } + }; + } +} \ No newline at end of file diff --git a/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java new file mode 100644 index 0000000000..a59bb30f48 --- /dev/null +++ b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/dao/FooDao.java @@ -0,0 +1,14 @@ +package org.baeldung.spring.persistence.dao; + +import org.springframework.stereotype.Repository; + +@Repository +public class FooDao implements IFooDao { + + public FooDao() { + super(); + } + + // API + +} diff --git a/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java new file mode 100644 index 0000000000..91d44f5f6b --- /dev/null +++ b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/dao/IFooDao.java @@ -0,0 +1,5 @@ +package org.baeldung.spring.persistence.dao; + +public interface IFooDao { + // +} diff --git a/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/model/Foo.java b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/model/Foo.java new file mode 100644 index 0000000000..8842c26d95 --- /dev/null +++ b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/model/Foo.java @@ -0,0 +1,31 @@ +package org.baeldung.spring.persistence.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Foo { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + public Foo() { + super(); + } + + // API + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + // + +} diff --git a/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/service/FooService.java b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/service/FooService.java new file mode 100644 index 0000000000..cda31a0e86 --- /dev/null +++ b/spring-hibernate3-dao/src/main/java/org/baeldung/spring/persistence/service/FooService.java @@ -0,0 +1,19 @@ +package org.baeldung.spring.persistence.service; + +import org.baeldung.spring.persistence.dao.IFooDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class FooService { + + @Autowired + private IFooDao fooDao; + + public FooService() { + super(); + } + + // API + +} diff --git a/spring-hibernate3-dao/src/main/resources/logback.xml b/spring-hibernate3-dao/src/main/resources/logback.xml new file mode 100644 index 0000000000..976d267d7d --- /dev/null +++ b/spring-hibernate3-dao/src/main/resources/logback.xml @@ -0,0 +1,60 @@ + + + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + /var/log/launchpad/launchpad_web.log + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + ERROR + + email-smtp.us-east-1.amazonaws.com + AKIAJI6XLSOAQX3IW6HQ + AuSWMdcNObKqGGT550SR/6vDrgh50vxgFrqZHwR2tTED + true + hanriseldon@gmail.com + info@applieddatalabs.com + TESTING: %logger{20} - %m + + web - |${launchpad.origin}| %date [%thread] %-5level %logger{36} - %message%n + + + 1000 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-hibernate3-dao/src/main/resources/persistence-mysql.properties b/spring-hibernate3-dao/src/main/resources/persistence-mysql.properties new file mode 100644 index 0000000000..a1ff997616 --- /dev/null +++ b/spring-hibernate3-dao/src/main/resources/persistence-mysql.properties @@ -0,0 +1,10 @@ +# jdbc.X +jdbc.driverClassName=com.mysql.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate_dao_01?createDatabaseIfNotExist=true +jdbc.user=tutorialuser +jdbc.pass=tutorialmy5ql + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop diff --git a/spring-hibernate3-dao/src/main/resources/webSecurityConfig.xml b/spring-hibernate3-dao/src/main/resources/webSecurityConfig.xml new file mode 100644 index 0000000000..5569cc6950 --- /dev/null +++ b/spring-hibernate3-dao/src/main/resources/webSecurityConfig.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-hibernate3-dao/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-hibernate3-dao/src/main/webapp/WEB-INF/mvc-servlet.xml new file mode 100644 index 0000000000..5463820874 --- /dev/null +++ b/spring-hibernate3-dao/src/main/webapp/WEB-INF/mvc-servlet.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/spring-hibernate3-dao/src/main/webapp/WEB-INF/view/sample.jsp b/spring-hibernate3-dao/src/main/webapp/WEB-INF/view/sample.jsp new file mode 100644 index 0000000000..7cc14b5dcd --- /dev/null +++ b/spring-hibernate3-dao/src/main/webapp/WEB-INF/view/sample.jsp @@ -0,0 +1,7 @@ + + + + +

This is the body of the sample view

+ + \ No newline at end of file diff --git a/spring-hibernate3-dao/src/main/webapp/WEB-INF/web.xml b/spring-hibernate3-dao/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..e0de9aefd4 --- /dev/null +++ b/spring-hibernate3-dao/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + Spring MVC Application + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + org.baeldung.spring.persistence.config + + + org.springframework.web.context.ContextLoaderListener + + \ No newline at end of file diff --git a/spring-hibernate3-dao/src/test/resources/.gitignore b/spring-hibernate3-dao/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-hibernate3-dao/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file