songtypeservice.java

来自「本代码是点歌系统的部分代码实现了部分功能」· Java 代码 · 共 54 行

JAVA
54
字号
package music.service;

import music.hibernate.SongType;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;



public class SongTypeService {
	


	public void insertSongType(SongType songtype)
	{
		SessionFactory sf = new Configuration().configure().buildSessionFactory();
		Session session = sf.openSession();
		Transaction tx = session.beginTransaction();
		
		session.save(songtype);
		tx.commit();
		session.close();
	}
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public SongType loadOneSongType(int i){
		SessionFactory sf = new Configuration().configure().buildSessionFactory();
		Session session = sf.openSession();
		Transaction tx = session.beginTransaction();
		SongType type = (SongType)session.get(SongType.class,i);
		tx.commit();
		session.close();
		return type;
	}
	
//	public MusicType loadOnMusicTypeName(Integer id)
//	{
//		SessionFactory sf = new Configuration().configure().buildSessionFactory();
//		Session session = sf.openSession();
//		
//		Transaction tx = session.beginTransaction();
//		String typeName = (String)session.get(MusicType.class, name);
//		tx.commit();
//		session.close();
//		return typeName;
//	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?