---
title: "公开SNS社区即时找朋友链的源代码和部署方案（续四）"
author: "markhe"
date: "2012-04-23T14:47:38Z"
tags: []
categories: ["数据库"]
slug: "sns"
draft: false
lastmod: "2012-04-23T14:47:38Z"
id: 1495425
url: "https://markhe.iteye.com/blog/1495425"
---

Versant数据库可以很容易地创建对象，并保存到数据库中。

		TransSession session = DistributedDatabaseManager.getInstance()
				.createNewSession();

		session.setDefaultDatabase("dbnodeb");
		
		// TransSession session = new TransSession("dbnodea");
		/**
		 * generate 500 random objects
		 */
		for (int i = 0; i < 1500; i++) {
			Person person = new Person();
			person.setFirstName("TFistName" + i);
			person.setLastName("TListName" + i);

			// set storage schema
			DistributedDatabaseManager.getInstance()
					.setRoundRobinPersistentSchema();

			session.makePersistent(person);
			session.commit();
		}

		System.out.println("Demo data generated.");
		session.commit();